diff options
Diffstat (limited to 'tests')
40 files changed, 910 insertions, 29 deletions
diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/AbsDouble.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/AbsDouble.cs index 6429a39ce4..f5650ab2c7 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/AbsDouble.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/AbsDouble.cs @@ -40,7 +40,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {absDoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {absDoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/AcosDouble.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/AcosDouble.cs index 3ba2867a8e..4df08bd063 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/AcosDouble.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/AcosDouble.cs @@ -40,7 +40,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {acosDoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {acosDoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/AsinDouble.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/AsinDouble.cs index 030756ce44..e20b65c422 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/AsinDouble.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/AsinDouble.cs @@ -40,7 +40,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {asinDoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {asinDoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/Atan2Double.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/Atan2Double.cs index 82831e6412..1fcde440af 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/Atan2Double.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/Atan2Double.cs @@ -41,7 +41,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {atan2DoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {atan2DoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/AtanDouble.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/AtanDouble.cs index ec2ebe389e..28619e8527 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/AtanDouble.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/AtanDouble.cs @@ -40,7 +40,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {atanDoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {atanDoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/CeilingDouble.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/CeilingDouble.cs index f822aae256..e28e9e67a5 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/CeilingDouble.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/CeilingDouble.cs @@ -40,7 +40,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {ceilingDoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {ceilingDoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/CosDouble.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/CosDouble.cs index e95ab5c241..faf69b0439 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/CosDouble.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/CosDouble.cs @@ -40,7 +40,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {cosDoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {cosDoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/CoshDouble.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/CoshDouble.cs index c8b7fb68cc..3a7e36d107 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/CoshDouble.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/CoshDouble.cs @@ -40,7 +40,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {coshDoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {coshDoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/ExpDouble.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/ExpDouble.cs index 64be83972f..9af1cb8e8b 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/ExpDouble.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/ExpDouble.cs @@ -40,7 +40,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {expDoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {expDoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/FloorDouble.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/FloorDouble.cs index 4d4b4f2f1b..158cc490df 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/FloorDouble.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/FloorDouble.cs @@ -40,7 +40,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {floorDoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {floorDoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/Log10Double.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/Log10Double.cs index 330d8a726b..32cd2163a5 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/Log10Double.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/Log10Double.cs @@ -40,7 +40,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {log10DoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {log10DoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/LogDouble.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/LogDouble.cs index bddb84b59c..38edbfbbd9 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/LogDouble.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/LogDouble.cs @@ -40,7 +40,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {logDoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {logDoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/PowDouble.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/PowDouble.cs index c8248072b7..f36d84e179 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/PowDouble.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/PowDouble.cs @@ -41,7 +41,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {powDoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {powDoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/RoundDouble.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/RoundDouble.cs index 9c5dcc9141..6c7a46992a 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/RoundDouble.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/RoundDouble.cs @@ -40,7 +40,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {roundDoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {roundDoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/SinDouble.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/SinDouble.cs index 73886aaa3a..c684b9530b 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/SinDouble.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/SinDouble.cs @@ -40,7 +40,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {sinDoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {sinDoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/SinhDouble.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/SinhDouble.cs index 8f79cc9576..69d1cb80da 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/SinhDouble.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/SinhDouble.cs @@ -40,7 +40,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {sinhDoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {sinhDoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/SqrtDouble.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/SqrtDouble.cs index 5d9e554684..59e73b3fcb 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/SqrtDouble.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/SqrtDouble.cs @@ -40,7 +40,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {sqrtDoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {sqrtDoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/TanDouble.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/TanDouble.cs index 6988c675dc..123948419f 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/TanDouble.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/TanDouble.cs @@ -40,7 +40,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {tanDoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {tanDoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/TanhDouble.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/TanhDouble.cs index c4809e53a3..526a428069 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/TanhDouble.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Double/TanhDouble.cs @@ -40,7 +40,7 @@ namespace Functions if (diff > doubleEpsilon) { - throw new Exception($"Expected Result {tanhDoubleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {tanhDoubleExpectedResult,20:g17}; Actual Result {result,20:g17}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Functions.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Functions.cs index 8ddc6ad73b..c9b1ef1147 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Functions.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Functions.cs @@ -24,23 +24,41 @@ namespace Functions ["absdouble"] = MathTests.AbsDoubleTest, ["abssingle"] = MathTests.AbsSingleTest, ["acosdouble"] = MathTests.AcosDoubleTest, + ["acossingle"] = MathTests.AcosSingleTest, ["asindouble"] = MathTests.AsinDoubleTest, + ["asinsingle"] = MathTests.AsinSingleTest, ["atandouble"] = MathTests.AtanDoubleTest, + ["atansingle"] = MathTests.AtanSingleTest, ["atan2double"] = MathTests.Atan2DoubleTest, + ["atan2single"] = MathTests.Atan2SingleTest, ["ceilingdouble"] = MathTests.CeilingDoubleTest, + ["ceilingsingle"] = MathTests.CeilingSingleTest, ["cosdouble"] = MathTests.CosDoubleTest, + ["cossingle"] = MathTests.CosSingleTest, ["coshdouble"] = MathTests.CoshDoubleTest, + ["coshsingle"] = MathTests.CoshSingleTest, ["expdouble"] = MathTests.ExpDoubleTest, + ["expsingle"] = MathTests.ExpSingleTest, ["floordouble"] = MathTests.FloorDoubleTest, + ["floorsingle"] = MathTests.FloorSingleTest, ["logdouble"] = MathTests.LogDoubleTest, + ["logsingle"] = MathTests.LogSingleTest, ["log10double"] = MathTests.Log10DoubleTest, + ["log10single"] = MathTests.Log10SingleTest, ["powdouble"] = MathTests.PowDoubleTest, + ["powsingle"] = MathTests.PowSingleTest, ["rounddouble"] = MathTests.RoundDoubleTest, + ["roundsingle"] = MathTests.RoundSingleTest, ["sindouble"] = MathTests.SinDoubleTest, + ["sinsingle"] = MathTests.SinSingleTest, ["sinhdouble"] = MathTests.SinhDoubleTest, + ["sinhsingle"] = MathTests.SinhSingleTest, ["sqrtdouble"] = MathTests.SqrtDoubleTest, + ["sqrtsingle"] = MathTests.SqrtSingleTest, ["tandouble"] = MathTests.TanDoubleTest, - ["tanhdouble"] = MathTests.TanhDoubleTest + ["tansingle"] = MathTests.TanSingleTest, + ["tanhdouble"] = MathTests.TanhDoubleTest, + ["tanhsingle"] = MathTests.TanhSingleTest }; private static int Main(string[] args) diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Functions.csproj b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Functions.csproj index 773472d4a4..2545a585bb 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Functions.csproj +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Functions.csproj @@ -9,7 +9,7 @@ <OutputType>Exe</OutputType> <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> - <NuGetTargetMoniker>.NETStandard,Version=v1.4</NuGetTargetMoniker> + <NuGetTargetMoniker>.NETCoreApp,Version=v1.1</NuGetTargetMoniker> </PropertyGroup> <!-- Default configurations to help VS understand the configurations --> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> @@ -29,8 +29,9 @@ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> </ItemGroup> <ItemGroup> + <Compile Include="Functions.cs" /> + <Compile Include="MathTests.cs" /> <Compile Include="Double\AbsDouble.cs" /> - <Compile Include="Single\AbsSingle.cs" /> <Compile Include="Double\AcosDouble.cs" /> <Compile Include="Double\AsinDouble.cs" /> <Compile Include="Double\AtanDouble.cs" /> @@ -40,10 +41,8 @@ <Compile Include="Double\CoshDouble.cs" /> <Compile Include="Double\ExpDouble.cs" /> <Compile Include="Double\FloorDouble.cs" /> - <Compile Include="Functions.cs" /> <Compile Include="Double\LogDouble.cs" /> <Compile Include="Double\Log10Double.cs" /> - <Compile Include="MathTests.cs" /> <Compile Include="Double\PowDouble.cs" /> <Compile Include="Double\RoundDouble.cs" /> <Compile Include="Double\SinDouble.cs" /> @@ -51,11 +50,26 @@ <Compile Include="Double\SqrtDouble.cs" /> <Compile Include="Double\TanDouble.cs" /> <Compile Include="Double\TanhDouble.cs" /> + <Compile Include="Single\AbsSingle.cs" /> + <Compile Include="Single\AcosSingle.cs" /> + <Compile Include="Single\AsinSingle.cs" /> + <Compile Include="Single\AtanSingle.cs" /> + <Compile Include="Single\Atan2Single.cs" /> + <Compile Include="Single\CeilingSingle.cs" /> + <Compile Include="Single\CosSingle.cs" /> + <Compile Include="Single\CoshSingle.cs" /> + <Compile Include="Single\ExpSingle.cs" /> + <Compile Include="Single\FloorSingle.cs" /> + <Compile Include="Single\LogSingle.cs" /> + <Compile Include="Single\Log10Single.cs" /> + <Compile Include="Single\PowSingle.cs" /> + <Compile Include="Single\RoundSingle.cs" /> + <Compile Include="Single\SinSingle.cs" /> + <Compile Include="Single\SinhSingle.cs" /> + <Compile Include="Single\SqrtSingle.cs" /> + <Compile Include="Single\TanSingle.cs" /> + <Compile Include="Single\TanhSingle.cs" /> </ItemGroup> - <PropertyGroup> - <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson> - <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson> - </PropertyGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> </PropertyGroup> diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/AbsSingle.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/AbsSingle.cs index 6168991297..8100c37e1d 100644 --- a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/AbsSingle.cs +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/AbsSingle.cs @@ -40,7 +40,7 @@ namespace Functions if (diff > singleEpsilon) { - throw new Exception($"Expected Result {absSingleExpectedResult}; Actual Result {result}"); + throw new Exception($"Expected Result {absSingleExpectedResult,10:g9}; Actual Result {result,10:g9}"); } } } diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/AcosSingle.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/AcosSingle.cs new file mode 100644 index 0000000000..b958cc1bb4 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/AcosSingle.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.Acos(float) over 5000 iterations for the domain -1, +1 + + private const float acosSingleDelta = 0.0004f; + private const float acosSingleExpectedResult = 7852.41084f; + + [Benchmark] + public static void AcosSingleBenchmark() + { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + AcosSingleTest(); + } + } + } + + public static void AcosSingleTest() + { + var result = 0.0f; var value = -1.0f; + + for (var iteration = 0; iteration < iterations; iteration++) + { + value += acosSingleDelta; + result += MathF.Acos(value); + } + + var diff = MathF.Abs(acosSingleExpectedResult - result); + + if (diff > singleEpsilon) + { + throw new Exception($"Expected Result {acosSingleExpectedResult,10:g9}; Actual Result {result,10:g9}"); + } + } + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/AsinSingle.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/AsinSingle.cs new file mode 100644 index 0000000000..917c49288f --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/AsinSingle.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.Asin(float) over 5000 iterations for the domain -1, +1 + + private const float asinSingleDelta = 0.0004f; + private const float asinSingleExpectedResult = 1.57079590f; + + [Benchmark] + public static void AsinSingleBenchmark() + { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + AsinSingleTest(); + } + } + } + + public static void AsinSingleTest() + { + var result = 0.0f; var value = -1.0f; + + for (var iteration = 0; iteration < iterations; iteration++) + { + value += asinSingleDelta; + result += MathF.Asin(value); + } + + var diff = MathF.Abs(asinSingleExpectedResult - result); + + if (diff > singleEpsilon) + { + throw new Exception($"Expected Result {asinSingleExpectedResult,10:g9}; Actual Result {result,10:g9}"); + } + } + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/Atan2Single.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/Atan2Single.cs new file mode 100644 index 0000000000..a3a4577947 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/Atan2Single.cs @@ -0,0 +1,48 @@ +// 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.Atan2(float, float) over 5000 iterations for the domain y: -1, +1; x: +1, -1 + + private const float atan2SingleDeltaX = -0.0004f; + private const float atan2SingleDeltaY = 0.0004f; + private const float atan2SingleExpectedResult = 3930.14282f; + + [Benchmark] + public static void Atan2SingleBenchmark() + { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + Atan2SingleTest(); + } + } + } + + public static void Atan2SingleTest() + { + var result = 0.0f; var valueX = 1.0f; var valueY = -1.0f; + + for (var iteration = 0; iteration < iterations; iteration++) + { + valueX += atan2SingleDeltaX; valueY += atan2SingleDeltaY; + result += MathF.Atan2(valueY, valueX); + } + + var diff = MathF.Abs(atan2SingleExpectedResult - result); + + if (diff > singleEpsilon) + { + throw new Exception($"Expected Result {atan2SingleExpectedResult,10:g9}; Actual Result {result,10:g9}"); + } + } + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/AtanSingle.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/AtanSingle.cs new file mode 100644 index 0000000000..95cc0e226e --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/AtanSingle.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.Atan(float) over 5000 iterations for the domain -1, +1 + + private const float atanSingleDelta = 0.0004f; + private const float atanSingleExpectedResult = 0.841940999f; + + [Benchmark] + public static void AtanSingleBenchmark() + { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + AtanSingleTest(); + } + } + } + + public static void AtanSingleTest() + { + var result = 0.0f; var value = -1.0f; + + for (var iteration = 0; iteration < iterations; iteration++) + { + value += atanSingleDelta; + result += MathF.Atan(value); + } + + var diff = MathF.Abs(atanSingleExpectedResult - result); + + if (diff > singleEpsilon) + { + throw new Exception($"Expected Result {atanSingleExpectedResult,10:g9}; Actual Result {result,10:g9}"); + } + } + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/CeilingSingle.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/CeilingSingle.cs new file mode 100644 index 0000000000..85454f1cc8 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/CeilingSingle.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.Ceiling(float) over 5000 iterations for the domain -1, +1 + + private const float ceilingSingleDelta = 0.0004f; + private const float ceilingSingleExpectedResult = 2502.0f; + + [Benchmark] + public static void CeilingSingleBenchmark() + { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + CeilingSingleTest(); + } + } + } + + public static void CeilingSingleTest() + { + var result = 0.0f; var value = -1.0f; + + for (var iteration = 0; iteration < iterations; iteration++) + { + value += ceilingSingleDelta; + result += MathF.Ceiling(value); + } + + var diff = MathF.Abs(ceilingSingleExpectedResult - result); + + if (diff > singleEpsilon) + { + throw new Exception($"Expected Result {ceilingSingleExpectedResult,10:g9}; Actual Result {result,10:g9}"); + } + } + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/CosSingle.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/CosSingle.cs new file mode 100644 index 0000000000..3d1d6a3b58 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/CosSingle.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.Cos(float) over 5000 iterations for the domain 0, PI + + private const float cosSingleDelta = 0.000628318531f; + private const float cosSingleExpectedResult = -0.993487537f; + + [Benchmark] + public static void CosSingleBenchmark() + { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + CosSingleTest(); + } + } + } + + public static void CosSingleTest() + { + var result = 0.0f; var value = 0.0f; + + for (var iteration = 0; iteration < iterations; iteration++) + { + value += cosSingleDelta; + result += MathF.Cos(value); + } + + var diff = MathF.Abs(cosSingleExpectedResult - result); + + if (diff > singleEpsilon) + { + throw new Exception($"Expected Result {cosSingleExpectedResult,10:g9}; Actual Result {result,10:g9}"); + } + } + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/CoshSingle.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/CoshSingle.cs new file mode 100644 index 0000000000..072a0dcf66 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/CoshSingle.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.Cosh(float) over 5000 iterations for the domain -1, +1 + + private const float coshSingleDelta = 0.0004f; + private const float coshSingleExpectedResult = 5876.02588f; + + [Benchmark] + public static void CoshSingleBenchmark() + { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + CoshSingleTest(); + } + } + } + + public static void CoshSingleTest() + { + var result = 0.0f; var value = -1.0f; + + for (var iteration = 0; iteration < iterations; iteration++) + { + value += coshSingleDelta; + result += MathF.Cosh(value); + } + + var diff = MathF.Abs(coshSingleExpectedResult - result); + + if (diff > singleEpsilon) + { + throw new Exception($"Expected Result {coshSingleExpectedResult,10:g9}; Actual Result {result,10:g9}"); + } + } + } +} 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..e9d61c9f5d --- /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.28564f; + + [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,10:g9}; Actual Result {result,10:g9}"); + } + } + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/FloorSingle.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/FloorSingle.cs new file mode 100644 index 0000000000..ce1febb178 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/FloorSingle.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.Floor(float) over 5000 iterations for the domain -1, +1 + + private const float floorSingleDelta = 0.0004f; + private const float floorSingleExpectedResult = -2498.0f; + + [Benchmark] + public static void FloorSingleBenchmark() + { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + FloorSingleTest(); + } + } + } + + public static void FloorSingleTest() + { + var result = 0.0f; var value = -1.0f; + + for (var iteration = 0; iteration < iterations; iteration++) + { + value += floorSingleDelta; + result += MathF.Floor(value); + } + + var diff = MathF.Abs(floorSingleExpectedResult - result); + + if (diff > singleEpsilon) + { + throw new Exception($"Expected Result {floorSingleExpectedResult,10:g9}; Actual Result {result,10:g9}"); + } + } + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/Log10Single.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/Log10Single.cs new file mode 100644 index 0000000000..80f00b3ec8 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/Log10Single.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.Log10(float) over 5000 iterations for the domain -1, +1 + + private const float log10SingleDelta = 0.0004f; + private const float log10SingleExpectedResult = -664.094971f; + + [Benchmark] + public static void Log10SingleBenchmark() + { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + Log10SingleTest(); + } + } + } + + public static void Log10SingleTest() + { + var result = 0.0f; var value = 0.0f; + + for (var iteration = 0; iteration < iterations; iteration++) + { + value += log10SingleDelta; + result += MathF.Log10(value); + } + + var diff = MathF.Abs(log10SingleExpectedResult - result); + + if (diff > singleEpsilon) + { + throw new Exception($"Expected Result {log10SingleExpectedResult,10:g9}; Actual Result {result,10:g9}"); + } + } + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/LogSingle.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/LogSingle.cs new file mode 100644 index 0000000000..3f07ef16ab --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/LogSingle.cs @@ -0,0 +1,48 @@ +// 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.Log(float) over 5000 iterations for the domain -1, +1 + + private const float logSingleDelta = 0.0004f; + private const float logSingleExpectedResult = -1529.14014f; + + [Benchmark] + public static void LogSingleBenchmark() + { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + LogSingleTest(); + } + } + } + + public static void LogSingleTest() + { + var result = 0.0f; var value = 0.0f; + + for (var iteration = 0; iteration < iterations; iteration++) + { + value += logSingleDelta; + result += MathF.Log(value); + } + + var diff = MathF.Abs(logSingleExpectedResult - result); + + if (diff > singleEpsilon) + { + throw new Exception($"Expected Result {logSingleExpectedResult,10:g9}; Actual Result {result,10:g9}"); + } + } + } + +} diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/PowSingle.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/PowSingle.cs new file mode 100644 index 0000000000..49de8a0101 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/PowSingle.cs @@ -0,0 +1,48 @@ +// 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.Pow(float, float) over 5000 iterations for the domain x: +2, +1; y: -2, -1 + + private const float powSingleDeltaX = -0.0004f; + private const float powSingleDeltaY = 0.0004f; + private const float powSingleExpectedResult = 4659.30762f; + + [Benchmark] + public static void PowSingleBenchmark() + { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + PowSingleTest(); + } + } + } + + public static void PowSingleTest() + { + var result = 0.0f; var valueX = 2.0f; var valueY = -2.0f; + + for (var iteration = 0; iteration < iterations; iteration++) + { + valueX += powSingleDeltaX; valueY += powSingleDeltaY; + result += MathF.Pow(valueX, valueY); + } + + var diff = MathF.Abs(powSingleExpectedResult - result); + + if (diff > singleEpsilon) + { + throw new Exception($"Expected Result {powSingleExpectedResult,10:g9}; Actual Result {result,10:g9}"); + } + } + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/RoundSingle.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/RoundSingle.cs new file mode 100644 index 0000000000..b494a2a985 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/RoundSingle.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.Round(float) over 5000 iterations for the domain -PI/2, +PI/2 + + private const float roundSingleDelta = 0.000628318531f; + private const float roundSingleExpectedResult = 2.0f; + + [Benchmark] + public static void RoundSingleBenchmark() + { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + RoundSingleTest(); + } + } + } + + public static void RoundSingleTest() + { + var result = 0.0f; var value = -1.57079633f; + + for (var iteration = 0; iteration < iterations; iteration++) + { + value += roundSingleDelta; + result += MathF.Round(value); + } + + var diff = MathF.Abs(roundSingleExpectedResult - result); + + if (diff > singleEpsilon) + { + throw new Exception($"Expected Result {roundSingleExpectedResult,10:g9}; Actual Result {result,10:g9}"); + } + } + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/SinSingle.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/SinSingle.cs new file mode 100644 index 0000000000..4d6228361e --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/SinSingle.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.Sin(float) over 5000 iterations for the domain -PI/2, +PI/2 + + private const float sinSingleDelta = 0.000628318531f; + private const float sinSingleExpectedResult = 1.03592682f; + + [Benchmark] + public static void SinSingleBenchmark() + { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + SinSingleTest(); + } + } + } + + public static void SinSingleTest() + { + var result = 0.0f; var value = -1.57079633f; + + for (var iteration = 0; iteration < iterations; iteration++) + { + value += sinSingleDelta; + result += MathF.Sin(value); + } + + var diff = MathF.Abs(sinSingleExpectedResult - result); + + if (diff > singleEpsilon) + { + throw new Exception($"Expected Result {sinSingleExpectedResult,10:g9}; Actual Result {result,10:g9}"); + } + } + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/SinhSingle.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/SinhSingle.cs new file mode 100644 index 0000000000..9ed01e4f55 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/SinhSingle.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.Sinh(float) over 5000 iterations for the domain -1, +1 + + private const float sinhSingleDelta = 0.0004f; + private const float sinhSingleExpectedResult = 1.26028216f; + + [Benchmark] + public static void SinhSingleBenchmark() + { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + SinhSingleTest(); + } + } + } + + public static void SinhSingleTest() + { + var result = 0.0f; var value = -1.0f; + + for (var iteration = 0; iteration < iterations; iteration++) + { + value += sinhSingleDelta; + result += MathF.Sinh(value); + } + + var diff = MathF.Abs(sinhSingleExpectedResult - result); + + if (diff > singleEpsilon) + { + throw new Exception($"Expected Result {sinhSingleExpectedResult,10:g9}; Actual Result {result,10:g9}"); + } + } + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/SqrtSingle.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/SqrtSingle.cs new file mode 100644 index 0000000000..f7349c1a5f --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/SqrtSingle.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.Sqrt(float) over 5000 iterations for the domain 0, PI + + private const float sqrtSingleDelta = 0.000628318531f; + private const float sqrtSingleExpectedResult = 5909.03027f; + + [Benchmark] + public static void SqrtSingleBenchmark() + { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + SqrtSingleTest(); + } + } + } + + public static void SqrtSingleTest() + { + var result = 0.0f; var value = 0.0f; + + for (var iteration = 0; iteration < iterations; iteration++) + { + value += sqrtSingleDelta; + result += MathF.Sqrt(value); + } + + var diff = MathF.Abs(sqrtSingleExpectedResult - result); + + if (diff > singleEpsilon) + { + throw new Exception($"Expected Result {sqrtSingleExpectedResult,10:g9}; Actual Result {result,10:g9}"); + } + } + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/TanSingle.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/TanSingle.cs new file mode 100644 index 0000000000..b81050bfa3 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/TanSingle.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.Tan(float) over 5000 iterations for the domain -PI/2, +PI/2 + + private const float tanSingleDelta = 0.0004f; + private const float tanSingleExpectedResult = 1.66717815f; + + [Benchmark] + public static void TanSingleBenchmark() + { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + TanSingleTest(); + } + } + } + + public static void TanSingleTest() + { + var result = 0.0f; var value = -1.0f; + + for (var iteration = 0; iteration < iterations; iteration++) + { + value += tanSingleDelta; + result += MathF.Tan(value); + } + + var diff = MathF.Abs(tanSingleExpectedResult - result); + + if (diff > singleEpsilon) + { + throw new Exception($"Expected Result {tanSingleExpectedResult,10:g9}; Actual Result {result,10:g9}"); + } + } + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/TanhSingle.cs b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/TanhSingle.cs new file mode 100644 index 0000000000..160e1135bf --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/Math/Functions/Single/TanhSingle.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.Tanh(float) over 5000 iterations for the domain -1, +1 + + private const float tanhSingleDelta = 0.0004f; + private const float tanhSingleExpectedResult = 0.816701353f; + + [Benchmark] + public static void TanhSingleBenchmark() + { + foreach (var iteration in Benchmark.Iterations) + { + using (iteration.StartMeasurement()) + { + TanhSingleTest(); + } + } + } + + public static void TanhSingleTest() + { + var result = 0.0f; var value = -1.0f; + + for (var iteration = 0; iteration < iterations; iteration++) + { + value += tanhSingleDelta; + result += MathF.Tanh(value); + } + + var diff = MathF.Abs(tanhSingleExpectedResult - result); + + if (diff > singleEpsilon) + { + throw new Exception($"Expected Result {tanhSingleExpectedResult,10:g9}; Actual Result {result,10:g9}"); + } + } + } +} |