-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.js
53 lines (42 loc) · 1.25 KB
/
benchmark.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
43
44
45
46
47
48
49
50
51
52
53
const varsof = require('./index.js');
const ITERATIONS = 100;
const ITERATIONS_INNER = 10000;
let object = {};
let start = Date.now(); // will replace Date.now with better perf measure
for (let i = 0; i < ITERATIONS; i++) {
for (let j = 0; j < ITERATIONS_INNER; j++) {
object._count = object._count ? object._count++ : 1;
varsof({}).foo = 'bar';
object[`property${j}`] = `value${100 - j}`;
}
let count = 0;
for (let j = 0; j < ITERATIONS_INNER; j++) {
if (object[`property${j}`] === `value${100 - j}`) {
count++;
}
}
if (count !== ITERATIONS_INNER) {
throw new Error();
}
}
let end = Date.now();
console.log(((end - start) / ITERATIONS) + 'ms average');
start = Date.now();
for (let i = 0; i < ITERATIONS; i++) {
for (let j = 0; j < ITERATIONS_INNER; j++) {
varsof(object)._count = varsof(object)._count ? varsof(object)._count++ : 1;
varsof({}).foo = 'bar';
varsof(object)[`property${j}`] = `value${100 - j}`;
}
let count = 0;
for (let j = 0; j < ITERATIONS_INNER; j++) {
if (varsof(object)[`property${j}`] === `value${100 - j}`) {
count++;
}
}
if (count !== ITERATIONS_INNER) {
throw new Error();
}
}
end = Date.now();
console.log(((end - start) / ITERATIONS) + 'ms average');