Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/otac0n/IronJS into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
fholm committed Apr 19, 2011
2 parents dd42f63 + f57787e commit 3c7727a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
38 changes: 26 additions & 12 deletions Src/Benchmarks/SunSpiderTestSuite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,22 @@ private static double GetDistribution(int n)
return Distribution[n];
}

private static string GetScore(IList<long> times)
{
var runs = times.Count;

var mean = times.Sum(t => (double)t) / runs;
var stdDev = Math.Sqrt((from i in times
let delta = i - mean
let deltaSq = delta * delta
select deltaSq).Sum() / (runs - 1));
var stdErr = stdDev / Math.Sqrt(Runs);
var confidence = ((GetDistribution(Runs) * stdErr / mean) * 100);
return Math.Round(mean, 1).ToString("0.0") + "ms ± " + Math.Round(confidence, 1).ToString("0.0") + "%";
}

protected override TestResult ExecuteTest(IronJS.Hosting.CSharp.Context ctx, string test)
{
var totalTime = TimeSpan.Zero;
var times = new List<long>();

try
Expand All @@ -45,7 +58,6 @@ protected override TestResult ExecuteTest(IronJS.Hosting.CSharp.Context ctx, str
ctx.ExecuteFile(test);
sw.Stop();

totalTime += sw.Elapsed;
times.Add(sw.ElapsedMilliseconds);
}
}
Expand All @@ -54,15 +66,7 @@ protected override TestResult ExecuteTest(IronJS.Hosting.CSharp.Context ctx, str
return new TestResult { Error = ex.GetBaseException().Message, Tag = Tuple.Create(test, Enumerable.Repeat(-1L, Runs).ToArray()) };
}

var mean = (double)totalTime.TotalMilliseconds / Runs;
var stdDev = Math.Sqrt((from i in times
let delta = i - mean
let deltaSq = delta * delta
select deltaSq).Sum() / (Runs - 1));
var stdErr = stdDev / Math.Sqrt(Runs);
var confidence = ((GetDistribution(Runs) * stdErr / mean) * 100);
var scoreString = Math.Round(mean, 1).ToString("0.0") + "ms +/- " + Math.Round(confidence, 1).ToString("0.0") + "%";
return new TestResult { Score = scoreString, Tag = Tuple.Create(test, times.ToArray()) };
return new TestResult { Score = GetScore(times), Tag = Tuple.Create(test, times.ToArray()) };
}

protected override TestResult AggregateResults(IList<TestResult> results)
Expand All @@ -89,7 +93,17 @@ protected override TestResult AggregateResults(IList<TestResult> results)
return new TestResult { Error = "Could not aggregate the score, because errors exist." };
}

return new TestResult { Score = "TODO: Calculate the total and 95% confidence interval for the suite." };
var runs = new long[Runs];
foreach (var result in results)
{
var t = (result.Tag as Tuple<string, long[]>).Item2;
for (int i = 0; i < Runs; i++)
{
runs[i] += t[i];
}
}

return new TestResult { Score = GetScore(runs) };
}
}
}
9 changes: 8 additions & 1 deletion Src/Benchmarks/V8BenchMarkTestSuite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ protected override TestResult AggregateResults(IList<TestResult> results)
return new TestResult { Error = "Could not aggregate the score, because errors exist." };
}

return new TestResult { Score = "TODO: Calculate the geometric mean of the results." };
var product = 1.0;
foreach (var r in results)
{
product *= double.Parse(r.Score);
}

var geometricMean = Math.Pow(product, 1.0 / results.Count);
return new TestResult { Score = Math.Round(geometricMean, 2).ToString("0.0") };
}
}
}

0 comments on commit 3c7727a

Please sign in to comment.