-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbench.js
43 lines (39 loc) · 1010 Bytes
/
bench.js
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
var WeakMap = require("./weak-map");
var keys = [];
for (var i = 0; i < 1000; i++) {
keys.push({});
}
var maps = [];
suite("WeakMap", function () {
bench("make", function () {
for (var i = 0; i < 100; i++) {
maps.push(new WeakMap());
}
});
bench("set", function () {
var map = maps[0];
for (var i = 0; i < keys.length; i++) {
map.set(keys[i], i);
}
});
bench("get", function () {
var map = maps[0];
for (var i = 0; i < keys.length; i++) {
map.get(keys[i]);
}
});
bench("sparse set", function () {
for (var j = 25; j < maps.length; j += 12) {
for (var i = 0; i < 10; i++) {
maps[j].set(keys[i], i);
}
}
});
bench("sparse get", function () {
for (var j = 25; j < maps.length; j += 12) {
for (var i = 0; i < 10; i++) {
maps[j].get(keys[i]);
}
}
});
});