-
Notifications
You must be signed in to change notification settings - Fork 51
/
map.perf.ts
70 lines (62 loc) · 1.32 KB
/
map.perf.ts
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
import * as _ from "lodash";
import { benchmark } from "./report";
import * as Immutable from "immutable";
import * as Finger from "@paldepind/finger-tree";
import * as Benchmark from "benchmark";
import * as L from "../../dist/index";
import * as Lo from "./list-old/dist/index";
function square(n: number): number {
return n * n;
}
let array = [];
let tree = Finger.nil;
let immut = Immutable.List();
let l = L.empty();
let lOld = Lo.empty();
benchmark(
{
name: "map",
description: "maps a function over a sequence.",
input: [20, 100, 500, 1000, 5000, 10000],
before: n => {
array = [];
immut = Immutable.List();
l = L.empty();
lOld = Lo.empty();
for (let i = 0; i < n; ++i) {
tree = Finger.append(i, tree);
immut = immut.push(i);
array.push(i);
l = L.append(i, l);
lOld = Lo.append(i, lOld);
}
}
},
{
List: {
run: () => {
return L.map(square, l);
}
},
"List, old": {
run: () => {
return Lo.map(square, lOld);
}
},
"Array#map": {
run: () => {
return array.map(square);
}
},
Lodash: {
run: () => {
return _.map(array, square);
}
},
"Immutable.js": {
run: () => {
return immut.map(square);
}
}
}
);