-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.js
More file actions
58 lines (53 loc) · 1.22 KB
/
benchmark.js
File metadata and controls
58 lines (53 loc) · 1.22 KB
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
import { Bench, hrtimeNow } from "tinybench";
import { immutate } from "./packages/immutable/src";
import { produce } from "immer";
import { create } from "mutative";
import { produce as sProduce } from "structurajs";
const bench = new Bench({ time: 100, now: hrtimeNow });
const o = [
{
title: "Learn TypeScript",
done: true,
},
{
title: "Try Immer",
done: false,
},
{
title: "New Todo",
done: false,
extraProp: null,
},
];
bench
.add("immutate", () => {
immutate(o, (draft) => {
draft[1].done = true;
delete draft[2].extraProp;
draft.push({ title: "Tweet about it" });
});
})
.add("structurajs", () => {
sProduce(o, (draft) => {
draft[1].done = true;
delete draft[2].extraProp;
draft.push({ title: "Tweet about it" });
});
})
.add("immer", () => {
produce(o, (draft) => {
draft[1].done = true;
delete draft[2].extraProp;
draft.push({ title: "Tweet about it" });
});
})
.add("mutative", () => {
create(o, (draft) => {
draft[1].done = true;
delete draft[2].extraProp;
draft.push({ title: "Tweet about it" });
});
});
await bench.warmup();
await bench.run();
console.table(bench.table());