Added some performance tests
This commit is contained in:
parent
3fefdccdf2
commit
c58cb0d00c
138
FastRngTests/Double/PerformanceTests.cs
Normal file
138
FastRngTests/Double/PerformanceTests.cs
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using FastRng.Double;
|
||||||
|
using FastRng.Double.Distributions;
|
||||||
|
using MathNet.Numerics.Distributions;
|
||||||
|
using MathNet.Numerics.Random;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
namespace FastRngTests.Double
|
||||||
|
{
|
||||||
|
[ExcludeFromCodeCoverage]
|
||||||
|
public class PerformanceTests
|
||||||
|
{
|
||||||
|
#region FastRng
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[Category(TestCategories.PERFORMANCE)]
|
||||||
|
public async Task Generate1MUniform()
|
||||||
|
{
|
||||||
|
using var rng = new MultiThreadedRng();
|
||||||
|
var data = new double[1_000_000];
|
||||||
|
var stopwatch = new Stopwatch();
|
||||||
|
Thread.Sleep(TimeSpan.FromSeconds(10)); // Warm-up phase of generator
|
||||||
|
|
||||||
|
stopwatch.Start();
|
||||||
|
for (uint n = 0; n < data.Length; n++)
|
||||||
|
data[n] = await rng.GetUniform();
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
|
|
||||||
|
TestContext.WriteLine($"Generated 1M uniform distributed random numbers in {stopwatch.Elapsed.Minutes} minute(s), {stopwatch.Elapsed.Seconds} second(s), and {stopwatch.Elapsed.Milliseconds} milliseconds.");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[Category(TestCategories.PERFORMANCE)]
|
||||||
|
public async Task Generate1MNormal()
|
||||||
|
{
|
||||||
|
using var rng = new MultiThreadedRng();
|
||||||
|
var dist = new NormalS02M05();
|
||||||
|
var data = new double[1_000_000];
|
||||||
|
var stopwatch = new Stopwatch();
|
||||||
|
Thread.Sleep(TimeSpan.FromSeconds(10)); // Warm-up phase of generator
|
||||||
|
|
||||||
|
stopwatch.Start();
|
||||||
|
for (uint n = 0; n < data.Length; n++)
|
||||||
|
data[n] = await rng.NextNumber(dist);
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
|
rng.StopProducer();
|
||||||
|
|
||||||
|
TestContext.WriteLine($"Generated 1M normal distributed random numbers in {stopwatch.Elapsed.Minutes} minute(s), {stopwatch.Elapsed.Seconds} second(s), and {stopwatch.Elapsed.Milliseconds} milliseconds.");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[Category(TestCategories.PERFORMANCE)]
|
||||||
|
public async Task Generate1MChiSquare()
|
||||||
|
{
|
||||||
|
using var rng = new MultiThreadedRng();
|
||||||
|
var dist = new ChiSquareK4();
|
||||||
|
var data = new double[1_000_000];
|
||||||
|
var stopwatch = new Stopwatch();
|
||||||
|
Thread.Sleep(TimeSpan.FromSeconds(10)); // Warm-up phase of generator
|
||||||
|
|
||||||
|
stopwatch.Start();
|
||||||
|
for (uint n = 0; n < data.Length; n++)
|
||||||
|
data[n] = await rng.NextNumber(dist);
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
|
|
||||||
|
TestContext.WriteLine($"Generated 1M chi-square distributed random numbers in {stopwatch.Elapsed.Minutes} minute(s), {stopwatch.Elapsed.Seconds} second(s), and {stopwatch.Elapsed.Milliseconds} milliseconds.");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Math.NET
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[Category(TestCategories.PERFORMANCE)]
|
||||||
|
public void ComparisonMathNet1MUniform()
|
||||||
|
{
|
||||||
|
var rng = new Xorshift(true);
|
||||||
|
var data = new float[1_000_000];
|
||||||
|
var stopwatch = new Stopwatch();
|
||||||
|
Thread.Sleep(TimeSpan.FromSeconds(10)); // Warm-up phase of generator
|
||||||
|
|
||||||
|
stopwatch.Start();
|
||||||
|
for (uint n = 0; n < data.Length; n++)
|
||||||
|
data[n] = (float) rng.NextDouble();
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
|
|
||||||
|
TestContext.WriteLine($"Generated 1M uniform distributed random numbers by means of Math.NET in {stopwatch.Elapsed.Minutes} minute(s), {stopwatch.Elapsed.Seconds} second(s), and {stopwatch.Elapsed.Milliseconds} milliseconds.");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[Category(TestCategories.PERFORMANCE)]
|
||||||
|
public void ComparisonMathNet1MNormal()
|
||||||
|
{
|
||||||
|
var rng = new Xorshift(true);
|
||||||
|
var dist = new Normal(stddev: 0.2f, mean: 0.5f, randomSource: rng);
|
||||||
|
var data = new float[1_000_000];
|
||||||
|
var stopwatch = new Stopwatch();
|
||||||
|
Thread.Sleep(TimeSpan.FromSeconds(10)); // Warm-up phase of generator
|
||||||
|
|
||||||
|
stopwatch.Start();
|
||||||
|
for (uint n = 0; n < data.Length; n++)
|
||||||
|
data[n] = (float) dist.Sample();
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
|
|
||||||
|
TestContext.WriteLine($"Generated 1M normal distributed random numbers by means of Math.NET in {stopwatch.Elapsed.Minutes} minute(s), {stopwatch.Elapsed.Seconds} second(s), and {stopwatch.Elapsed.Milliseconds} milliseconds.");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[Category(TestCategories.PERFORMANCE)]
|
||||||
|
public void ComparisonMathNet1MChiSquare()
|
||||||
|
{
|
||||||
|
var rng = new Xorshift(true);
|
||||||
|
var dist = new ChiSquared(4);
|
||||||
|
var data = new float[1_000_000];
|
||||||
|
var stopwatch = new Stopwatch();
|
||||||
|
Thread.Sleep(TimeSpan.FromSeconds(10)); // Warm-up phase of generator
|
||||||
|
|
||||||
|
stopwatch.Start();
|
||||||
|
for (uint n = 0; n < data.Length; n++)
|
||||||
|
data[n] = (float) dist.Sample();
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
|
|
||||||
|
TestContext.WriteLine($"Generated 1M chi-squared distributed random numbers by means of Math.NET in {stopwatch.Elapsed.Minutes} minute(s), {stopwatch.Elapsed.Seconds} second(s), and {stopwatch.Elapsed.Milliseconds} milliseconds.");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
@ -20,7 +20,7 @@ namespace FastRngTests.Float
|
|||||||
[Category(TestCategories.PERFORMANCE)]
|
[Category(TestCategories.PERFORMANCE)]
|
||||||
public async Task Generate1MUniform()
|
public async Task Generate1MUniform()
|
||||||
{
|
{
|
||||||
var rng = new MultiThreadedRng();
|
using var rng = new MultiThreadedRng();
|
||||||
var data = new float[1_000_000];
|
var data = new float[1_000_000];
|
||||||
var stopwatch = new Stopwatch();
|
var stopwatch = new Stopwatch();
|
||||||
Thread.Sleep(TimeSpan.FromSeconds(10)); // Warm-up phase of generator
|
Thread.Sleep(TimeSpan.FromSeconds(10)); // Warm-up phase of generator
|
||||||
@ -30,7 +30,6 @@ namespace FastRngTests.Float
|
|||||||
data[n] = await rng.GetUniform();
|
data[n] = await rng.GetUniform();
|
||||||
|
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
rng.StopProducer();
|
|
||||||
|
|
||||||
TestContext.WriteLine($"Generated 1M uniform distributed random numbers in {stopwatch.Elapsed.Minutes} minute(s), {stopwatch.Elapsed.Seconds} second(s), and {stopwatch.Elapsed.Milliseconds} milliseconds.");
|
TestContext.WriteLine($"Generated 1M uniform distributed random numbers in {stopwatch.Elapsed.Minutes} minute(s), {stopwatch.Elapsed.Seconds} second(s), and {stopwatch.Elapsed.Milliseconds} milliseconds.");
|
||||||
}
|
}
|
||||||
@ -39,7 +38,7 @@ namespace FastRngTests.Float
|
|||||||
[Category(TestCategories.PERFORMANCE)]
|
[Category(TestCategories.PERFORMANCE)]
|
||||||
public async Task Generate1MNormal()
|
public async Task Generate1MNormal()
|
||||||
{
|
{
|
||||||
var rng = new MultiThreadedRng();
|
using var rng = new MultiThreadedRng();
|
||||||
var dist = new NormalS02M05();
|
var dist = new NormalS02M05();
|
||||||
var data = new float[1_000_000];
|
var data = new float[1_000_000];
|
||||||
var stopwatch = new Stopwatch();
|
var stopwatch = new Stopwatch();
|
||||||
@ -59,8 +58,8 @@ namespace FastRngTests.Float
|
|||||||
[Category(TestCategories.PERFORMANCE)]
|
[Category(TestCategories.PERFORMANCE)]
|
||||||
public async Task Generate1MChiSquare()
|
public async Task Generate1MChiSquare()
|
||||||
{
|
{
|
||||||
var rng = new MultiThreadedRng();
|
using var rng = new MultiThreadedRng();
|
||||||
var dist = new ChiSquareK4();
|
var dist = new ChiSquareK4(); // TODO: Check the impact, when the rng gets set on ctor
|
||||||
var data = new float[1_000_000];
|
var data = new float[1_000_000];
|
||||||
var stopwatch = new Stopwatch();
|
var stopwatch = new Stopwatch();
|
||||||
Thread.Sleep(TimeSpan.FromSeconds(10)); // Warm-up phase of generator
|
Thread.Sleep(TimeSpan.FromSeconds(10)); // Warm-up phase of generator
|
||||||
@ -70,7 +69,6 @@ namespace FastRngTests.Float
|
|||||||
data[n] = await rng.NextNumber(dist);
|
data[n] = await rng.NextNumber(dist);
|
||||||
|
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
rng.StopProducer();
|
|
||||||
|
|
||||||
TestContext.WriteLine($"Generated 1M chi-square distributed random numbers in {stopwatch.Elapsed.Minutes} minute(s), {stopwatch.Elapsed.Seconds} second(s), and {stopwatch.Elapsed.Milliseconds} milliseconds.");
|
TestContext.WriteLine($"Generated 1M chi-square distributed random numbers in {stopwatch.Elapsed.Minutes} minute(s), {stopwatch.Elapsed.Seconds} second(s), and {stopwatch.Elapsed.Milliseconds} milliseconds.");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user