-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcat-methods.js
52 lines (47 loc) · 1.16 KB
/
concat-methods.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
const b = require("benny");
const fs = require("fs");
b.suite(
"Concat methods",
b.add(".concat", () => {
const a = Array.from({ length: 10000 }, (_x, i) => i);
const b = Array.from({ length: 10000 }, (_x, i) => i * 3);
return () => {
a.concat(b);
};
}),
b.add("spread", () => {
const a = Array.from({ length: 10000 }, (_x, i) => i);
const b = Array.from({ length: 10000 }, (_x, i) => i * 3);
return () => {
[...a, ...b];
};
}),
b.add("push", () => {
const a = Array.from({ length: 10000 }, (_x, i) => i);
const b = Array.from({ length: 10000 }, (_x, i) => i * 3);
return () => {
let res = [];
for (let item of a) {
res.push(item);
}
for (let item of b) {
res.push(item);
}
};
}),
b.add("push for", () => {
const a = Array.from({ length: 10000 }, (_x, i) => i);
const b = Array.from({ length: 10000 }, (_x, i) => i * 3);
return () => {
let res = [];
for (let i = 0; i < a.length; i++) {
res.push(a[i]);
}
for (let i = 0; i < b.length; i++) {
res.push(b[i]);
}
};
}),
b.cycle(),
b.complete()
);