summaryrefslogtreecommitdiff
path: root/tests/src/JIT/Performance/CodeQuality/BenchF/NewtE/NewtE.cs
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2016-11-23 19:09:09 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2016-11-23 19:09:09 +0900
commit4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (patch)
tree98110734c91668dfdbb126fcc0e15ddbd93738ca /tests/src/JIT/Performance/CodeQuality/BenchF/NewtE/NewtE.cs
parentfa45f57ed55137c75ac870356a1b8f76c84b229c (diff)
downloadcoreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.gz
coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.bz2
coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.zip
Imported Upstream version 1.1.0upstream/1.1.0
Diffstat (limited to 'tests/src/JIT/Performance/CodeQuality/BenchF/NewtE/NewtE.cs')
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchF/NewtE/NewtE.cs135
1 files changed, 135 insertions, 0 deletions
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/NewtE/NewtE.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/NewtE/NewtE.cs
new file mode 100644
index 0000000000..0fc14132f1
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/BenchF/NewtE/NewtE.cs
@@ -0,0 +1,135 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// Simultaneous equations by Newton's method adapted from Conte and De Boor
+// to solve F(X,Y)=0 and G(X,Y)=0
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public static class NewtE
+{
+#if DEBUG
+ public const int Iterations = 1;
+#else
+ public const int Iterations = 1000000;
+#endif
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ private static bool Bench()
+ {
+ double idgb, a, b, x, y, deltaX, deltaY;
+ a = 0;
+ b = 0;
+ x = 0;
+ y = 0;
+ idgb = 0;
+
+ if (idgb != 0)
+ {
+ System.Console.WriteLine("{0}, {1}, F(x,y) , G(x,y) \n", x, y);
+ }
+
+ for (int j = 1; j <= Iterations; j++)
+ {
+ x = 1.0;
+ y = (-2.0);
+ a = F(x, y);
+ b = G(x, y);
+ if (idgb != 0)
+ {
+ System.Console.WriteLine(" {0}, {1}, {2}, {3}\n", x, y, a, b);
+ }
+
+ for (int i = 1; i <= 20; i++)
+ {
+ deltaX = (-F(x, y) * GY(x, y) + G(x, y) * FY(x, y)) / (FX(x, y) * GY(x, y) - FY(x, y) * GX(x, y));
+ deltaY = (-G(x, y) * FX(x, y) + F(x, y) * GX(x, y)) / (FX(x, y) * GY(x, y) - FY(x, y) * GX(x, y));
+ x = x + deltaX;
+ y = y + deltaY;
+ a = F(x, y);
+ b = G(x, y);
+ if (idgb != 0)
+ {
+ System.Console.WriteLine("{0}, {1}, {2}, {3}, {4}\n", i, x, y, a, b);
+ }
+
+ if ((System.Math.Abs(deltaX) < 0.000001) && (System.Math.Abs(deltaY) < 0.000001) &&
+ (System.Math.Abs(a) < 0.000001) && (System.Math.Abs(b) < 0.000001))
+ {
+ goto L11;
+ }
+ }
+ if (idgb != 0)
+ {
+ System.Console.WriteLine("FAILED TO CONVERGE IN 20 ITERATIONS\n");
+ }
+
+ L11:
+ {
+ }
+ }
+
+ return true;
+ }
+
+ private static double F(double x, double y)
+ {
+ return ((x) + 3 * System.Math.Log(x) / System.Math.Log(10.0) - (y) * (y));
+ }
+
+ private static double G(double x, double y)
+ {
+ return (2 * (x) * (x) - (x) * (y) - 5 * (x) + 1);
+ }
+
+ private static double FX(double x, double y)
+ {
+ return (1 + 3 / (System.Math.Log(10.0) * (x)));
+ }
+
+ private static double FY(double x, double y)
+ {
+ return ((-2) * (y));
+ }
+
+ private static double GX(double x, double y)
+ {
+ return (4 * (x) - (y) - 5);
+ }
+
+ private static double GY(double x, double y)
+ {
+ return (-(x));
+ }
+
+ [Benchmark]
+ public static void Test()
+ {
+ foreach (var iteration in Benchmark.Iterations)
+ {
+ using (iteration.StartMeasurement())
+ {
+ Bench();
+ }
+ }
+ }
+
+ private static bool TestBase()
+ {
+ bool result = Bench();
+ return result;
+ }
+
+ public static int Main()
+ {
+ bool result = TestBase();
+ return (result ? 100 : -1);
+ }
+}