-
Notifications
You must be signed in to change notification settings - Fork 51
/
prepend.perf.ts
114 lines (111 loc) · 2.28 KB
/
prepend.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { benchmark } from "./report";
import * as L from "../../dist/index";
import * as Lo from "./list-old/dist/index";
import * as _ from "lodash";
import * as Immutable from "immutable";
import * as R from "ramda";
import * as mori from "mori";
let n = 0;
benchmark(
{
name: "append",
description:
"Constructs a sequence of size n by repeatedly appending to it.",
input: [10, 50, 100, 250, 500, 1000, 5000, 10000]
},
{
List: {
before: nn => {
n = nn;
},
run: () => {
let list = L.empty();
for (let i = 0; i < n; ++i) {
list = L.append(i, list);
}
return list.length === n;
}
},
"List, old": {
before: nn => {
n = nn;
},
run: () => {
let list = Lo.empty();
for (let i = 0; i < n; ++i) {
list = Lo.append(i, list);
}
return list.length === n;
}
},
"Immutable.js": {
before: nn => {
n = nn;
},
run: () => {
let imm = Immutable.List();
for (let i = 0; i < n; ++i) {
imm = imm.push(i);
}
return imm.size === n;
}
},
Ramda: {
before: nn => {
n = nn;
},
run: () => {
let arr: number[] = [];
for (let i = 0; i < n; ++i) {
arr = R.append(i, arr);
}
return arr.length === n;
}
},
Mori: {
before: nn => {
n = nn;
},
run: () => {
let list = mori.vector();
for (let i = 0; i < n; ++i) {
list = mori.conj(list, i);
}
return mori.count(list);
}
}
}
);
benchmark(
{
name: "prepend",
description: "Creates a sequence of size n by repeatedly prepending.",
input: [10, 100, 500, 1000]
},
{
List: {
before: nn => {
n = nn;
},
run: () => {
let list = L.empty();
for (let i = 0; i < n; ++i) {
list = L.prepend(i, list);
}
return list.length === n;
}
},
"Old list": {
before: nn => {
n = nn;
},
run: () => {
let list = Lo.empty();
for (let i = 0; i < n; ++i) {
list = Lo.prepend(i, list);
}
return list.length === n;
}
}
}
);