diff options
author | Tanner Gooding <tagoo@outlook.com> | 2017-02-05 13:41:37 -0800 |
---|---|---|
committer | Tanner Gooding <tagoo@microsoft.com> | 2017-05-16 11:33:14 -0700 |
commit | 4807b9fc40a8d5644df9dd15e0f43bd307fab395 (patch) | |
tree | 486eaa5053af37e28d0781f57759fb24dfbac2e0 /tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/ExpSingle.cs | |
parent | f2913a39793be26a5bb598582c41790593a5e5f8 (diff) | |
download | coreclr-4807b9fc40a8d5644df9dd15e0f43bd307fab395.tar.gz coreclr-4807b9fc40a8d5644df9dd15e0f43bd307fab395.tar.bz2 coreclr-4807b9fc40a8d5644df9dd15e0f43bd307fab395.zip |
Adding perf tests for the single precision math functions in System.MathF.
Diffstat (limited to 'tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/ExpSingle.cs')
-rw-r--r-- | tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/ExpSingle.cs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/ExpSingle.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/ExpSingle.cs new file mode 100644 index 0000000000..c68812d068 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/ExpSingle.cs @@ -0,0 +1,47 @@ +// 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. + +using System; +using Microsoft.Xunit.Performance; + +namespace Functions +{ + public static partial class MathTests + { + // Tests MathF.Exp(float) over 5000 iterations for the domain -1, +1 + + private const float expSingleDelta = 0.0004f; + private const float expSingleExpectedResult = 5877.18125f; + + [Benchmark] + public static void ExpSingleBenchmark() + { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + ExpSingleTest(); + } + } + } + + public static void ExpSingleTest() + { + var result = 0.0f; var value = -1.0f; + + for (var iteration = 0; iteration < iterations; iteration++) + { + value += expSingleDelta; + result += MathF.Exp(value); + } + + var diff = MathF.Abs(expSingleExpectedResult - result); + + if (diff > singleEpsilon) + { + throw new Exception($"Expected Result {expSingleExpectedResult}; Actual Result {result}"); + } + } + } +} |