Fix validation of spectralnorm under xunit-performance
authorAndy Ayers <andya@microsoft.com>
Mon, 11 Apr 2016 21:21:56 +0000 (14:21 -0700)
committerAndy Ayers <andya@microsoft.com>
Mon, 11 Apr 2016 21:21:56 +0000 (14:21 -0700)
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

src/coreclr/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/spectralnorm/spectralnorm.cs

index fa2ac08..9e98486 100644 (file)
@@ -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");
+            }
         }
     }