forked from cynthia/mt.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmt19937.html
More file actions
154 lines (112 loc) · 3.25 KB
/
Copy pathmt19937.html
File metadata and controls
154 lines (112 loc) · 3.25 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<html>
<head>
<script src="mt19937.js"></script>
<script>
var mt;
var start_time;
var end_time;
var results = [0, 0, 0, 0, 0, 0, 0, 0];
var run_count = 1000;
var tmp;
function benchmark_seeding()
{
start_time = new Date();
for (var i = 0; i < run_count; i++)
tmp = mt.init();
end_time = new Date() - start_time;
results[0] = end_time;
}
function benchmark_seeding_with_seed()
{
start_time = new Date();
for (var i = 0; i < run_count; i++)
tmp = mt.init(4357);
end_time = new Date() - start_time;
results[1] = end_time;
}
function benchmark_ints()
{
start_time = new Date();
for (var i = 0; i < run_count; i++)
tmp = mt.nextInt();
end_time = new Date() - start_time;
results[2] = end_time;
}
function benchmark_ints_with_max()
{
start_time = new Date();
for (var i = 0; i < run_count; i++)
tmp = mt.nextInt(100);
end_time = new Date() - start_time;
results[3] = end_time;
}
function benchmark_ints_with_minmax()
{
start_time = new Date();
for (var i = 0; i < run_count; i++)
tmp = mt.nextInt(1, 100);
end_time = new Date() - start_time;
results[4] = end_time;
}
function benchmark_floats()
{
start_time = new Date();
for (var i = 0; i < run_count; i++)
tmp = mt.next();
end_time = new Date() - start_time;
results[5] = end_time;
}
function benchmark_floats_with_max()
{
start_time = new Date();
for (var i = 0; i < run_count; i++)
tmp = mt.next(5.5);
end_time = new Date() - start_time;
results[6] = end_time;
}
function benchmark_floats_with_minmax()
{
start_time = new Date();
for (var i = 0; i < run_count; i++)
tmp = mt.next(0.5, 5.5);
end_time = new Date() - start_time;
results[7] = end_time;
}
function start()
{
mt = new MersenneTwister();
document.getElementById('count').innerHTML = run_count;
benchmark_seeding();
benchmark_seeding_with_seed();
benchmark_ints();
benchmark_ints_with_max();
benchmark_ints_with_minmax();
benchmark_floats();
benchmark_floats_with_max();
benchmark_floats_with_minmax();
document.getElementById('res_0').innerHTML = results[0];
document.getElementById('res_1').innerHTML = results[1];
document.getElementById('res_2').innerHTML = results[2];
document.getElementById('res_3').innerHTML = results[3];
document.getElementById('res_4').innerHTML = results[4];
document.getElementById('res_5').innerHTML = results[5];
document.getElementById('res_6').innerHTML = results[6];
document.getElementById('res_7').innerHTML = results[7];
}
</script>
</head>
<body onload="start();">
<h1>mt.js Benchmark Results</h1>
<h3>Benchmark rounds performed per item: <span id="count">0</span></h3>
<ul>
<li>Seeding with dynamic seed: <span id="res_0">0</span>ms</li>
<li>Seeding with static seed: <span id="res_1">0</span>ms</li>
<li>Ints: <span id="res_2">0</span>ms</li>
<li>Ints with max: <span id="res_3">0</span>ms</li>
<li>Ints with min/max: <span id="res_4">0</span>ms</li>
<li>Floats: <span id="res_5">0</span>ms</li>
<li>Floats with max: <span id="res_6">0</span>ms</li>
<li>Floats with min/max: <span id="res_7">0</span>ms</li>
</ul>
</body>
</html>