-
Notifications
You must be signed in to change notification settings - Fork 2
/
benchmarker.html
83 lines (66 loc) · 2.68 KB
/
benchmarker.html
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
<html>
<head>
<title>Js Suffix Trie benchmarker</title>
<script src="benchmark/test_array.js" type="text/javascript"></script>
<script src="js_suffix_trie.js" type="text/javascript"></script>
<style type="text/css">
ul { list-style-type: none; margin: 0px; padding: 0px; }
label { display: inline-block; width: 250px; }
</style>
<script type="text/javascript">
var suffixTrie = new JsSuffixTrie();
for (var i = 0, l = array.length; i < l; i++) {
suffixTrie.add(array[i]);
}
function uiBenchmark() {
benchmark(
parseInt(document.getElementById("benchmarks").value),
parseInt(document.getElementById("calls").value)
);
}
function benchmark(number, n) {
var name = "DONALD";
if (n === undefined) {
n = 1000000;
}
if (number === undefined) {
number = 1;
}
for (var i = 0; i < number; i++) {
console.time("Array ");
for (var j = 0; j < n; j++) {
array.indexOf(name);
}
console.timeEnd("Array ");
console.time("JsSuffixTrie");
for (var j = 0; j < n; j++) {
suffixTrie.contains(name);
}
console.timeEnd("JsSuffixTrie");
}
}
</script>
</head>
<body>
<h1>Js Suffix Trie benchmarker</h1>
<p>
<a href="https://github.com/martijnversluis/JsSuffixTrie">https://github.com/martijnversluis/JsSuffixTrie</a>
</p>
<form action="">
<ul>
<li>
<label for="benchmarks">Number of benchmarks:</label>
<input id="benchmarks" name="benchmarks" type="text" value="10"/>
</li>
<li>
<label for="calls">Number of calls per benchmark:</label>
<input id="calls" name="calls" type="text" value="1000000"/>
</li>
</ul>
</form>
<p>
<button onclick="uiBenchmark()">Start benchmark</button>
</p>
<p>Open your JavaScript console to see the results</p>
</body>
</html>