-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmarkold.d
More file actions
88 lines (78 loc) · 2.54 KB
/
benchmarkold.d
File metadata and controls
88 lines (78 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import std.datetime, std.random, std.range, std.stdio, std.typetuple;
// $(D TypeTuple) of all uniform RNGs defined in std.random.
alias UniformRNGTypes =
TypeTuple!(MinstdRand0, MinstdRand,
Mt19937,
Xorshift32, Xorshift64, Xorshift128, Xorshift160, Xorshift192);
void main()
{
enum k = 10_000;
enum l = 1_000_000;
enum m = 10_000_000;
enum n = 100_000_000;
foreach (UniformRNG; UniformRNGTypes)
{
StopWatch watch;
auto rng = UniformRNG(unpredictableSeed);
writeln("Testing random generator: ", typeof(rng).stringof);
writeln("\tfront: ", rng.front);
watch.start();
rng.popFrontN(n);
watch.stop();
writeln("\tfront after ", n, " pops: ", rng.front);
writeln("\tcalculated in ", watch.peek.msecs, " ms.");
auto proportions = cycle([1, 2, 3, 4, 5]).take(100).array;
watch.reset();
watch.start();
foreach (immutable _; 0 .. m)
{
auto d = dice(rng, proportions);
}
watch.stop();
writeln("\t", watch.peek.msecs, " ms. to perform ", m, " calls to dice.");
watch.reset();
watch.start();
foreach (immutable _; 0 .. m)
{
auto u = uniform(0.0, 1.0, rng);
}
watch.stop();
writeln("\t", watch.peek.msecs, " ms. to perform ", m, " calls to uniform.");
watch.reset();
watch.start();
foreach (immutable _; 0 .. k)
{
auto cover = randomCover(proportions, rng);
foreach (c; cover)
{
auto val = c;
}
}
watch.stop();
writeln("\t", watch.peek.msecs, " ms. to generate ", k, " random covers of ",
proportions.length, " elements.");
watch.reset();
watch.start();
foreach (immutable _; 0 .. l)
{
auto sample = randomSample(proportions, 5, rng);
foreach (s; sample)
{
auto val = s;
}
}
watch.stop();
writeln("\t", watch.peek.msecs, " ms. to generate ", l, " random samples of 5 out of ",
proportions.length, " elements.");
watch.reset();
watch.start();
foreach (immutable _; 0 .. l)
{
randomShuffle(proportions, rng);
}
watch.stop();
writeln("\t", watch.peek.msecs, " ms. to generate ", l, " in-place random shuffles of ",
proportions.length, " elements.");
writeln();
}
}