summaryrefslogtreecommitdiff
path: root/tests/src
diff options
context:
space:
mode:
authorNatalia Glagoleva <natgla@microsoft.com>2016-03-30 18:57:19 -0700
committerNatalia Glagoleva <natgla@microsoft.com>2016-03-30 18:57:19 -0700
commitf32f0b30a2fc05cb63b2e2ab8873db37a5c6c75c (patch)
tree0f51a908404a164c76b0054d0d76ea27e91475f9 /tests/src
parentf914a011b7764327ac7b008372e2e4970b50980d (diff)
downloadcoreclr-f32f0b30a2fc05cb63b2e2ab8873db37a5c6c75c.tar.gz
coreclr-f32f0b30a2fc05cb63b2e2ab8873db37a5c6c75c.tar.bz2
coreclr-f32f0b30a2fc05cb63b2e2ab8873db37a5c6c75c.zip
Changes from code review
Added verification to the benchmark, put most of output under #if VERBOSE. Also fixed number of iterations for xunit.perf runs.
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchF/Adams/Adams.cs91
1 files changed, 56 insertions, 35 deletions
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Adams/Adams.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/Adams/Adams.cs
index ab4bdc0101..eeb98a6cf2 100644
--- a/tests/src/JIT/Performance/CodeQuality/BenchF/Adams/Adams.cs
+++ b/tests/src/JIT/Performance/CodeQuality/BenchF/Adams/Adams.cs
@@ -11,12 +11,12 @@ using System.Diagnostics;
#if XUNIT_PERF
using Xunit;
using Microsoft.Xunit.Performance;
-#endif
+#endif // XUNIT_PERF
#if XUNIT_PERF
[assembly: OptimizeForBenchmarks]
[assembly: MeasureInstructionsRetired]
-#endif
+#endif // XUNIT_PERF
public static class Adams
{
@@ -24,9 +24,13 @@ public static class Adams
public static int Iterations = 1;
#else
public static int Iterations = 200000;
-#endif
+#endif // DEBUG
static double g_xn, g_yn, g_dn, g_en;
+ const double g_xn_base = 0.09999999E+01;
+ const double g_yn_base = 0.71828180E+00;
+ const double g_dn_base = 0.21287372E-08;
+ const double g_en_base = 0.74505806E-08;
[MethodImpl(MethodImplOptions.NoInlining)]
private static void Bench()
@@ -35,9 +39,9 @@ public static class Adams
double xn, yn, dn, en, yxn, h, fnp, ynp, y0, x0, nz;
int i, k, n, nstep;
-#if DEBUG
+#if VERBOSE
Console.WriteLine(" ADAMS-MOULTON METHOD ");
-#endif // DEBUG
+#endif // VERBOSE
n = 4;
h = 1.0 / 32.0;
@@ -51,9 +55,9 @@ public static class Adams
nz = 0;
f[1] = x0 + y0;
-#if DEBUG
+#if VERBOSE
Console.WriteLine("{0}, {1}, {2}, {3}, {4}", nz, x0, y0, dn, en);
-#endif // DEBUG
+#endif // VERBOSE
xn = x0;
for (i = 2; i <= 4; i++)
{
@@ -61,9 +65,9 @@ public static class Adams
xn = xn + h;
yn = Soln(xn);
f[i] = xn + yn;
-#if DEBUG
+#if VERBOSE
Console.WriteLine("{0}, {1}, {2}, {3}, {4}", k, xn, yn, dn, en);
-#endif // DEBUG
+#endif // VERBOSE
}
for (k = 4; k <= nstep; k++)
@@ -79,16 +83,16 @@ public static class Adams
f[n] = xn + yn;
yxn = Soln(xn);
en = yn - yxn;
-#if DEBUG
+#if VERBOSE
Console.WriteLine("{0}, {1}, {2}, {3}, {4}", k, xn, yn, dn, en);
-#endif // DEBUG
+#endif // VERBOSE
}
// Escape calculated values:
- g_xn += xn;
- g_yn += yn;
- g_dn += dn;
- g_en += en;
+ g_xn = xn;
+ g_yn = yn;
+ g_dn = dn;
+ g_en = en;
}
private static double Soln(double x)
@@ -96,6 +100,28 @@ public static class Adams
return (System.Math.Exp(x) - 1.0 - (x));
}
+ [MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
+ private static bool TestBench()
+ {
+ for (int l = 1; l <= Iterations; l++)
+ {
+ Bench();
+ }
+
+ bool result = true;
+ // Note: we can't check xn or yn better because of the precision
+ // with which original results are given
+ result &= System.Math.Abs(g_xn_base - g_xn) <= 1.5e-7;
+ result &= System.Math.Abs(g_yn_base - g_yn) <= 1.5e-7;
+ result &= System.Math.Abs(g_dn) <= 2.5e-9;
+ // Actual error is much bigger than base error;
+ // this is likely due to the fact that the original program was written in Fortran
+ // and was running on a mainframe with a non-IEEE floating point arithmetic
+ // (it's still beyond the published precision of yn)
+ result &= System.Math.Abs(g_en) <= 5.5e-8;
+ return result;
+ }
+
#if XUNIT_PERF
[Benchmark]
public static void Test()
@@ -104,13 +130,12 @@ public static class Adams
{
using (iteration.StartMeasurement())
{
- Bench();
+ TestBench();
}
}
}
-#endif
+#endif // XUNIT_PERF
- [MethodImpl(MethodImplOptions.NoOptimization)]
public static int Main(string[] argv)
{
if (argv.Length > 0)
@@ -119,25 +144,21 @@ public static class Adams
}
Stopwatch sw = Stopwatch.StartNew();
-
- for (int l = 1; l <= Iterations; l++)
- {
- Bench();
- }
+ bool result = TestBench();
sw.Stop();
- Console.WriteLine("Test iterations: {0}; Total time: {1} sec", Iterations, sw.Elapsed.TotalSeconds);
+ Console.WriteLine(result ? "Passed" : "Failed");
- Console.WriteLine(" BASE.....P1 1/4 (ADAMS-MOULTON), XN = .09999999E +01");
- Console.WriteLine(" VERIFY...P1 1/4 (ADAMS-MOULTON), XN = {0}\n", g_xn / Iterations);
- Console.WriteLine(" BASE.....P1 2/4 (ADAMS-MOULTON), YN = .71828180E+00");
- Console.WriteLine(" VERIFY...P1 2/4 (ADAMS-MOULTON), YN = {0}\n", g_yn / Iterations);
- Console.WriteLine(" BASE.....P1 3/4 (ADAMS-MOULTON), DN = .21287372E-08");
- Console.WriteLine(" VERIFY...P1 3/4 (ADAMS-MOULTON), DN = {0}\n", g_dn / Iterations);
- Console.WriteLine(" BASE.....P1 4/4 (ADAMS-MOULTON), EN = .74505806E-08");
- Console.WriteLine(" VERIFY...P1 4/4 (ADAMS-MOULTON), EN = {0}", g_en / Iterations);
-
- Console.WriteLine("Passed");
- return (100);
+ Console.WriteLine(" BASE.....P1 1/4 (ADAMS-MOULTON), XN = {0}", g_xn_base);
+ Console.WriteLine(" VERIFY...P1 1/4 (ADAMS-MOULTON), XN = {0}\n", g_xn);
+ Console.WriteLine(" BASE.....P1 2/4 (ADAMS-MOULTON), YN = {0}", g_yn_base);
+ Console.WriteLine(" VERIFY...P1 2/4 (ADAMS-MOULTON), YN = {0}\n", g_yn);
+ Console.WriteLine(" BASE.....P1 3/4 (ADAMS-MOULTON), DN = {0}", g_dn_base);
+ Console.WriteLine(" VERIFY...P1 3/4 (ADAMS-MOULTON), DN = {0}\n", g_dn);
+ Console.WriteLine(" BASE.....P1 4/4 (ADAMS-MOULTON), EN = {0}", g_en_base);
+ Console.WriteLine(" VERIFY...P1 4/4 (ADAMS-MOULTON), EN = {0}\n", g_en);
+
+ Console.WriteLine("Test iterations: {0}; Total time: {1} sec", Iterations, sw.Elapsed.TotalSeconds);
+ return (result ? 100 : -1);
}
}