-
Notifications
You must be signed in to change notification settings - Fork 51
/
map.suite.js
54 lines (44 loc) · 1.11 KB
/
map.suite.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
const Suite = require("./default-suite").Suite;
const Immutable = require("immutable");
const _ = require("lodash");
const List = require("../../dist/index");
const OldList = require("./list-old/dist/index");
const result = 1;
const suite = Suite("map");
function square(n) {
return n * n;
}
function addBenchmark(n) {
let array = [];
let immut = new Immutable.List();
let list = List.empty();
let oldList = OldList.empty();
for (let i = 0; i < n; ++i) {
list = list.append(i);
oldList = oldList.append(i);
array.push(i);
immut = immut.push(i);
}
suite
.add("Array#map " + n, function() {
return array.map(square);
})
.add("Lodash " + n, function() {
return _.map(array, square);
})
.add("Immutable.js " + n, function() {
return immut.map(square);
})
.add("mapArray " + n, function() {
return List.mapArray(square, array);
})
.add("List " + n, function() {
return List.map(square, list);
});
}
addBenchmark(10);
// addBenchmark(50);
// addBenchmark(100);
addBenchmark(1000);
suite.run({ async: true });
module.exports = suite;