/
array-population.js
87 lines (65 loc) · 1020 Bytes
/
array-population.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
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
"use strict";
var speedy = require ("../lib");
var a1 = [], i1 = 0;
var a2 = [], i2 = 0;
var a3 = [], i3 = 0;
var n = 100;
speedy.run ({
push: function (){
if (i1 === n){
a1 = [];
i1 = 0;
}
i1++;
a1.push (1);
},
length: function (){
if (i2 === n){
a2 = [];
i2 = 0;
}
i2++;
a2[a2.length] = 1;
},
index: function (){
if (i3 === n){
a3 = [];
i3 = 0;
}
a3[i3++] = 1;
}
});
/*
The results vary depending on the array length
File: array-population.js
Node v0.10.20
V8 v3.14.5.9
Speedy v0.1.0
Tests: 3
Timeout: 1000ms (1s 0ms)
Samples: 3
Total time per test: ~3000ms (3s 0ms)
Total time: ~9000ms (9s 0ms)
Higher is better (ops/sec)
n = 100
push
82,890,473 ± 0.0%
length
52,293,355 ± 0.1%
index
52,790,295 ± 0.0%
n = 10000
push
71,426,828 ± 0.0%
length
70,783,269 ± 0.2%
index
72,458,042 ± 0.0%
n = 1000000
push
23,369,209 ± 0.6%
length
19,272,770 ± 0.0%
index
19,180,275 ± 0.3%
*/