source: misc/tools/HeuristicLab.Benchmarks/HeuristicLab.Benchmarks/Random/RandomPerformance.cs @ 16300

Last change on this file since 16300 was 16300, checked in by bburlacu, 9 months ago

#2963: Add README.txt and remove unsupported code from benchmarks.

File size: 1.2 KB
Line 
1using BenchmarkDotNet.Attributes;
2using HeuristicLab.Core;
3using HeuristicLab.Random;
4
5namespace HeuristicLab.Benchmarks {
6  [CoreJob, ClrJob, MonoJob]
7  [MinColumn, MaxColumn, MeanColumn, MedianColumn]
8  public class RandomPerformance {
9    private readonly IRandom mersenneTwister = new MersenneTwister(1234);
10    private readonly IRandom fastRandom = new FastRandom(1234);
11
12    [Params(1_000_000)]
13    public int N { get; set; }
14
15    [Benchmark] public double FastRandomInt() => IntPerformance(fastRandom);
16    [Benchmark] public double MersenneTwisterInt() => IntPerformance(mersenneTwister);
17
18    [Benchmark] public double FastRandomDouble() => DoublePerformance(fastRandom);
19    [Benchmark] public double MersenneTwisterDouble() => DoublePerformance(mersenneTwister);
20
21    #region helper methods
22    private double IntPerformance(IRandom random) {
23      double avg = 0;
24      for (int i = 0; i < N; ++i) {
25        avg += random.Next();
26      }
27      return avg;
28    }
29
30    private double DoublePerformance(IRandom random) {
31      double avg = 0;
32      for (int i = 0; i < N; ++i) {
33        avg += random.NextDouble();
34      }
35      return avg;
36    }
37    #endregion
38  }
39}
Note: See TracBrowser for help on using the repository browser.