From: Andy Ayers Date: Mon, 11 Apr 2016 21:21:56 +0000 (-0700) Subject: Fix validation of spectralnorm under xunit-performance X-Git-Tag: submit/tizen/20210909.063632~11030^2~10879^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e8e2aec696107b71450f2ac8c7edadaa11bb5764;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Fix validation of spectralnorm under xunit-performance The valiation code wasn't correctly for the iteration strategy used by xunit-performance. Closes dotnet/coreclr#4270. Commit migrated from https://github.com/dotnet/coreclr/commit/73a947cde48114ef3989d84112d67b6a6f746c64 --- diff --git a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/spectralnorm/spectralnorm.cs b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/spectralnorm/spectralnorm.cs index fa2ac08..9e98486 100644 --- a/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/spectralnorm/spectralnorm.cs +++ b/src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/spectralnorm/spectralnorm.cs @@ -38,9 +38,10 @@ public class SpectralNorm public static void Bench() { int n = 100; - double a = 0; foreach (var iteration in Benchmark.Iterations) { + double a = 0; + using (iteration.StartMeasurement()) { for (int i = 0; i < Iterations; i++) @@ -49,13 +50,14 @@ public class SpectralNorm a += s.Approximate(n); } } - } - double norm = a / (n * Iterations); - double expected = 1.274219991; - bool valid = Math.Abs(norm - expected) < 1e-4; - if (!valid) - { - throw new Exception("Benchmark failed to validate"); + + double norm = a / Iterations; + double expected = 1.274219991; + bool valid = Math.Abs(norm - expected) < 1e-4; + if (!valid) + { + throw new Exception("Benchmark failed to validate"); + } } }