summaryrefslogtreecommitdiff
path: root/tests/src/JIT/Performance/CodeQuality
diff options
context:
space:
mode:
authorNatalia Glagoleva <natgla@microsoft.com>2016-03-25 14:59:26 -0700
committerNatalia Glagoleva <natgla@microsoft.com>2016-03-25 14:59:26 -0700
commit92cd3b1950f572b46b1cd84ccb20126d91172c57 (patch)
treeca144abd0acb10897b9b14c2ac747d324afd8b2e /tests/src/JIT/Performance/CodeQuality
parent764c9b52cfb7f631cc30ed23e7072c6eb04e195f (diff)
downloadcoreclr-92cd3b1950f572b46b1cd84ccb20126d91172c57.tar.gz
coreclr-92cd3b1950f572b46b1cd84ccb20126d91172c57.tar.bz2
coreclr-92cd3b1950f572b46b1cd84ccb20126d91172c57.zip
Changing adams benchmark
Changing benchmark to be closer to C code; conditionally excluding xunit.performance usage
Diffstat (limited to 'tests/src/JIT/Performance/CodeQuality')
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchF/Adams/Adams.cs131
1 files changed, 84 insertions, 47 deletions
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Adams/Adams.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/Adams/Adams.cs
index 0edc8b9218..9febc6c52d 100644
--- a/tests/src/JIT/Performance/CodeQuality/BenchF/Adams/Adams.cs
+++ b/tests/src/JIT/Performance/CodeQuality/BenchF/Adams/Adams.cs
@@ -3,37 +3,41 @@
// See the LICENSE file in the project root for more information.
//
// The Adams-Moulton Predictor Corrector Method adapted from Conte and de Boor
+// original source: adams_d.c
-using Microsoft.Xunit.Performance;
using System;
using System.Runtime.CompilerServices;
+using System.Diagnostics;
+#if XUNIT_PERF
using Xunit;
+using Microsoft.Xunit.Performance;
+#endif
+#if XUNIT_PERF
[assembly: OptimizeForBenchmarks]
[assembly: MeasureInstructionsRetired]
+#endif
public static class Adams
{
#if DEBUG
- public const int Iterations = 1;
+ public static int Iterations = 1;
#else
- public const int Iterations = 200000;
+ public static int Iterations = 10000000;
#endif
- public static volatile object VolatileObject;
-
- [MethodImpl(MethodImplOptions.NoInlining)]
- private static void Escape(object obj)
- {
- VolatileObject = obj;
- }
+ static double g_xn, g_yn, g_dn, g_en;
[MethodImpl(MethodImplOptions.NoInlining)]
- private static bool Bench()
+ private static void Bench()
{
double[] f = new double[5];
- double xn, yn, h, fnp, ynp, y0, x0;
- int i, k, l, n, nstep;
+ double xn, yn, dn, en, yxn, h, fnp, ynp, y0, x0, nz;
+ int i, k, n, nstep;
+
+#if DEBUG
+ Console.WriteLine(" ADAMS-MOULTON METHOD ");
+#endif // DEBUG
n = 4;
h = 1.0 / 32.0;
@@ -42,37 +46,49 @@ public static class Adams
x0 = 0.0;
xn = 0.0;
yn = 0.0;
+ dn = 0.0;
+ en = 0.0;
+ nz = 0;
- for (l = 1; l <= Iterations; l++)
+ f[1] = x0 + y0;
+#if DEBUG
+ Console.WriteLine("{0}, {1}, {2}, {3}, {4}", nz, x0, y0, dn, en);
+#endif // DEBUG
+ xn = x0;
+ for (i = 2; i <= 4; i++)
{
- f[1] = x0 + y0;
-
- xn = x0;
- for (i = 2; i <= 4; i++)
- {
- k = i - 1;
- xn = xn + h;
- yn = Soln(xn);
- f[i] = xn + yn;
- }
-
- for (k = 4; k <= nstep; k++)
- {
- ynp = yn + (h / 24) * (55 * f[n] - 59 * f[n - 1] + 37 * f[n - 2] - 9 * f[n - 3]);
- xn = xn + h;
- fnp = xn + ynp;
- yn = yn + (h / 24) * (9 * fnp + 19 * f[n] - 5 * f[n - 1] + f[n - 2]);
- f[n - 3] = f[n - 2];
- f[n - 2] = f[n - 1];
- f[n - 1] = f[n];
- f[n] = xn + yn;
- }
+ k = i - 1;
+ xn = xn + h;
+ yn = Soln(xn);
+ f[i] = xn + yn;
+#if DEBUG
+ Console.WriteLine("{0}, {1}, {2}, {3}, {4}", k, xn, yn, dn, en);
+#endif // DEBUG
}
- // Escape f so that its elements will be live-out
- Escape(f);
+ for (k = 4; k <= nstep; k++)
+ {
+ ynp = yn + (h / 24) * (55 * f[n] - 59 * f[n - 1] + 37 * f[n - 2] - 9 * f[n - 3]);
+ xn = xn + h;
+ fnp = xn + ynp;
+ yn = yn + (h / 24) * (9 * fnp + 19 * f[n] - 5 * f[n - 1] + f[n - 2]);
+ dn = (yn - ynp) / 14;
+ f[n - 3] = f[n - 2];
+ f[n - 2] = f[n - 1];
+ f[n - 1] = f[n];
+ f[n] = xn + yn;
+ yxn = Soln(xn);
+ en = yn - yxn;
+#if DEBUG
+ Console.WriteLine("{0}, {1}, {2}, {3}, {4}", k, xn, yn, dn, en);
+#endif // DEBUG
+ }
- return true;
+ // Escape calculated values:
+ g_xn += xn;
+ g_yn += yn;
+ g_dn += dn;
+ g_en += en;
}
private static double Soln(double x)
@@ -80,6 +96,7 @@ public static class Adams
return (System.Math.Exp(x) - 1.0 - (x));
}
+#if XUNIT_PERF
[Benchmark]
public static void Test()
{
@@ -91,16 +108,36 @@ public static class Adams
}
}
}
+#endif
- private static bool TestBase()
+ [MethodImpl(MethodImplOptions.NoOptimization)]
+ public static int Main(string[] argv)
{
- bool result = Bench();
- return result;
- }
+ if (argv.Length > 0)
+ {
+ Iterations = Int32.Parse(argv[0]);
+ }
- public static int Main()
- {
- bool result = TestBase();
- return (result ? 100 : -1);
+ Stopwatch sw = Stopwatch.StartNew();
+
+ for (int l = 1; l <= Iterations; l++)
+ {
+ Bench();
+ }
+ sw.Stop();
+
+ Console.WriteLine("Test iterations: {0}; Total time: {1} sec", Iterations, sw.Elapsed.TotalSeconds);
+
+ 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);
}
}