From 2e682c914a3b317db7d73f98cc43af763f5b7ab0 Mon Sep 17 00:00:00 2001 From: David Zar Date: Sun, 1 Feb 2015 11:20:18 +0200 Subject: [PATCH] Adding speedup and copy as html --- FishBench/MainForm.Designer.cs | 16 ++++---- FishBench/MainForm.cs | 71 ++++++++++++++++++++++++++++++---- FishBench/Tester.cs | 7 ++++ 3 files changed, 79 insertions(+), 15 deletions(-) diff --git a/FishBench/MainForm.Designer.cs b/FishBench/MainForm.Designer.cs index 07ab5b2..56664cd 100644 --- a/FishBench/MainForm.Designer.cs +++ b/FishBench/MainForm.Designer.cs @@ -187,21 +187,21 @@ private void InitializeComponent() // // resultsBox // - this.resultsBox.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.resultsBox.Font = new System.Drawing.Font("Courier New", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.resultsBox.Location = new System.Drawing.Point(15, 150); this.resultsBox.Multiline = true; this.resultsBox.Name = "resultsBox"; - this.resultsBox.Size = new System.Drawing.Size(307, 106); - this.resultsBox.TabIndex = 9; + this.resultsBox.Size = new System.Drawing.Size(307, 124); + this.resultsBox.TabIndex = 20; this.resultsBox.Text = "Results for 0 tests for each version:\r\n\r\n Base Test Diff " + " \r\n Mean 0 0 0 \r\n StDev 0 0 " + - "0 \r\n\r\np-value: 0"; + "0 \r\n\r\np-value: 0\r\nspeedup: 0"; // // copyButton // - this.copyButton.Location = new System.Drawing.Point(328, 233); + this.copyButton.Location = new System.Drawing.Point(328, 250); this.copyButton.Name = "copyButton"; - this.copyButton.Size = new System.Drawing.Size(75, 23); + this.copyButton.Size = new System.Drawing.Size(89, 23); this.copyButton.TabIndex = 10; this.copyButton.Text = "Copy"; this.copyButton.UseVisualStyleBackColor = true; @@ -211,7 +211,7 @@ private void InitializeComponent() // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(449, 268); + this.ClientSize = new System.Drawing.Size(449, 285); this.Controls.Add(this.copyButton); this.Controls.Add(this.resultsBox); this.Controls.Add(this.progressMessage); @@ -250,8 +250,8 @@ private void InitializeComponent() private System.Windows.Forms.Label progressLabel; private System.Windows.Forms.Label progressMessage; private System.Windows.Forms.Button terminateButton; - private System.Windows.Forms.TextBox resultsBox; private System.Windows.Forms.Button copyButton; + private System.Windows.Forms.TextBox resultsBox; } } diff --git a/FishBench/MainForm.cs b/FishBench/MainForm.cs index 112fdc8..485f34c 100644 --- a/FishBench/MainForm.cs +++ b/FishBench/MainForm.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Microsoft.Office.Interop.Word; namespace FishBench { @@ -44,6 +45,7 @@ public MainForm() try { amountTestNumeric.Value = result; } catch { amountTestNumeric.Value = 5; } t = new Tester(); + initHtml(); } private void locationText_TextChanged(object sender, EventArgs e) @@ -97,7 +99,7 @@ private void startButton_Click(object sender, EventArgs e) t = new Tester(baseLocationText.Text, stockfishLocationText.Text); t.Amount = (int)amountTestNumeric.Value; - setResult(0, 0, 0, 0, 0, 0, 0, 0); + setResult(0, 0, 0, 0, 0, 0, 0, 0, 0); progressBar.Value = 0; progressMessage.Text = string.Format(finishedMask, 0, (int)amountTestNumeric.Value * 2); @@ -107,7 +109,8 @@ private void startButton_Click(object sender, EventArgs e) { progressBar.SetAsync("Value", (int)t.PercentCompleted); progressMessage.SetAsync("Text", string.Format(finishedMask, t.Completed, t.Amount)); - setResult(t.AverageA, t.AverageB, t.AverageDiff, t.StdevA, t.StdevB, t.StdevDiff, t.CompletedEach, Math.Round(t.p_value, 3)); + setResult(t.AverageA, t.AverageB, t.AverageDiff, t.StdevA, t.StdevB, t.StdevDiff, t.CompletedEach, + Math.Round(t.p_value, 3), Math.Round(t.speedup, 3)); }; t.JobFinished += delegate { @@ -140,19 +143,23 @@ private void terminateButton_Click(object sender, EventArgs e) string resultLineFormat = " {0,-8}{1,-10}{2,-10}{3,-10}\r\n"; private void setResult(object baseMean, object testMean, object diffMean, object baseStdev, object testStdev, object diffStdev, - object testAmount, object pval) + object testAmount, object pval, object speedup) { resultsBox.SetAsync("Text", "Results for " + testAmount.ToString() + " tests for each version:\r\n\r\n" + string.Format(resultLineFormat, "", "Base", "Test", "Diff") + string.Format(resultLineFormat, "Mean", baseMean, testMean, diffMean) + string.Format(resultLineFormat, "StDev", baseStdev, testStdev, diffStdev) + - "\r\np-value: " + pval.ToString()); + "\r\np-value: " + pval.ToString() + "\r\nspeedup: " + speedup.ToString()); + htmlText = String.Format(htmlFormat, testAmount, baseMean, testMean, diffMean, + baseStdev, testStdev, diffStdev, pval, speedup); } - + private string htmlText, htmlFormat; private void copyButton_Click(object sender, EventArgs e) { - Clipboard.SetText(resultsBox.Text); + DataObject obj = HtmlToDataObject(htmlText); + obj.SetText(resultsBox.Text); + Clipboard.SetDataObject(obj); copyButton.BackColor = Color.PaleGreen; Timer t = new Timer(); t.Tick += delegate @@ -160,8 +167,58 @@ private void copyButton_Click(object sender, EventArgs e) t.Stop(); copyButton.BackColor = SystemColors.Control; }; - t.Interval = 1000; + t.Interval = 400; t.Start(); } + private void initHtml() + { + htmlFormat = ""; + htmlFormat += "Results for {0} tests for each version:
"; + htmlFormat += ""; + htmlFormat += ""; + htmlFormat += ""; + htmlFormat += ""; + htmlFormat += "
BaseTestDiff
Mean{1}{2}{3}
StDev{4}{5}{6}
"; + htmlFormat += "p-value: {7:P2}
"; + htmlFormat += "speedup: {8:P2}
"; + htmlFormat = htmlFormat.Replace("\r\n" + + "HTML clipboard\r\n\r\n\r\n" + + ""; + + string html_end = "\r\n\r\n\r\n"; + + string begin_sample = String.Format(begin, 0, 0, 0, 0); + + int count_begin = enc.GetByteCount(begin_sample); + int count_html_begin = enc.GetByteCount(html_begin); + int count_html = enc.GetByteCount(html); + int count_html_end = enc.GetByteCount(html_end); + + string html_total = String.Format( + begin + , count_begin + , count_begin + count_html_begin + count_html + count_html_end + , count_begin + count_html_begin + , count_begin + count_html_begin + count_html + ) + html_begin + html + html_end; + + DataObject obj = new DataObject(); + obj.SetData(DataFormats.Html, new MemoryStream( + enc.GetBytes(html_total))); + + return obj; + } } } diff --git a/FishBench/Tester.cs b/FishBench/Tester.cs index 169eecd..c846937 100644 --- a/FishBench/Tester.cs +++ b/FishBench/Tester.cs @@ -111,6 +111,13 @@ public double p_value } } + public double speedup + { + get + { + return (-(double)AverageDiff) / (double)AverageA; + } + } public Tester(string pathA, string pathB) { this.pathA = pathA;