-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmarknew.d
More file actions
124 lines (106 loc) · 3.53 KB
/
benchmarknew.d
File metadata and controls
124 lines (106 loc) · 3.53 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import std.datetime, hap.random, std.range, std.stdio;
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 = new 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.");
auto ddist = discreteDistribution(rng, proportions);
watch.reset();
watch.start();
ddist.popFrontN(m);
watch.stop();
writeln("\t", watch.peek.msecs, " ms. to perform ", m, " pops of ", typeof(ddist).stringof);
auto ndist = normalDistribution(0.0, 1.0, rng);
watch.reset();
watch.start();
ndist.popFrontN(m);
watch.stop();
writeln("\t", watch.peek.msecs, " ms. to perform ", m, " pops of ",
typeof(ndist).stringof);
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.");
auto udist = uniformDistribution(0.0, 1.0, rng);
watch.reset();
watch.start();
udist.popFrontN(m);
watch.stop();
writeln("\t", watch.peek.msecs, " ms. to perform ", m, " pops of ", typeof(udist).stringof);
watch.reset();
watch.start();
foreach (immutable _; 0 .. m)
{
auto u = uniform01(rng);
}
watch.stop();
writeln("\t", watch.peek.msecs, " ms. to perform ", m, " calls to uniform01.");
auto u01dist = uniform01Distribution(rng);
watch.reset();
watch.start();
u01dist.popFrontN(m);
watch.stop();
writeln("\t", watch.peek.msecs, " ms. to perform ", m, " pops of ", typeof(u01dist).stringof);
watch.reset();
watch.start();
foreach (immutable _; 0 .. k)
{
auto c = cover(proportions, rng);
foreach (e; c)
{
auto val = e;
}
}
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 s = sample(proportions, 5, rng);
foreach (e; s)
{
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)
{
shuffle(proportions, rng);
}
watch.stop();
writeln("\t", watch.peek.msecs, " ms. to generate ", l, " in-place random shuffles of ",
proportions.length, " elements.");
writeln();
}
}