Skip to content

Commit

Permalink
Adding speedup and copy as html
Browse files Browse the repository at this point in the history
  • Loading branch information
zardav committed Feb 1, 2015
1 parent 1d40664 commit 2e682c9
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 15 deletions.
16 changes: 8 additions & 8 deletions FishBench/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 64 additions & 7 deletions FishBench/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word;

namespace FishBench
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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
{
Expand Down Expand Up @@ -140,28 +143,82 @@ 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
{
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:<br>";
htmlFormat += "<table dir=\"ltr\">";
htmlFormat += "<tr><td></td><td>Base</td><td>Test</td><td>Diff</td></tr>";
htmlFormat += "<tr><td>Mean</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>";
htmlFormat += "<tr><td>StDev</td><td>{4}</td><td>{5}</td><td>{6}</td></tr>";
htmlFormat += "</table>";
htmlFormat += "p-value: {7:P2}<br>";
htmlFormat += "speedup: {8:P2}<br>";
htmlFormat = htmlFormat.Replace("<td", "<td style=\"padding: 6px\"");
htmlText = string.Format(htmlFormat, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
public static DataObject HtmlToDataObject(string html)
{
Encoding enc = Encoding.UTF8;

string begin = "Version:0.9\r\nStartHTML:{0:000000}\r\nEndHTML:{1:000000}"
+ "\r\nStartFragment:{2:000000}\r\nEndFragment:{3:000000}\r\n";

string html_begin = "<html>\r\n<head>\r\n"
+ "<meta http-equiv=\"Content-Type\""
+ " content=\"text/html; charset=" + enc.WebName + "\">\r\n"
+ "<title>HTML clipboard</title>\r\n</head>\r\n<body>\r\n"
+ "<!--StartFragment-->";

string html_end = "<!--EndFragment-->\r\n</body>\r\n</html>\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;
}
}
}
7 changes: 7 additions & 0 deletions FishBench/Tester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2e682c9

Please sign in to comment.