-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.js
74 lines (68 loc) · 1.89 KB
/
benchmark.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import benchmark from "benchmark";
import * as ulid from "ulid";
import init, * as waUlid from "./dist/index.esm.js";
await init();
const now = Date.now();
const sampleUlid = ulid.ulid();
const monotonicUlid = ulid.monotonicFactory();
const monotonicwaUlid = waUlid.monotonicFactory();
new benchmark.Suite()
.add("ulid.encodeTime", function () {
ulid.encodeTime(now, 10);
})
.add("wa-ulid.encodeTime", function () {
waUlid.encodeTime(now, 10);
})
.on("cycle", function (event) {
console.log(String(event.target));
})
.on("complete", function () {
console.log("encodeTime comparison complete. Fastest is " + this.filter("fastest").map("name"));
})
.run();
new benchmark.Suite()
.add("ulid.decodeTime", function () {
ulid.decodeTime(sampleUlid);
})
.add("wa-ulid.decodeTime", function () {
waUlid.decodeTime(sampleUlid);
})
.on("cycle", function (event) {
console.log(String(event.target));
})
.on("complete", function () {
console.log("decodeTime comparison complete. Fastest is " + this.filter("fastest").map("name"));
})
.run();
new benchmark.Suite()
.add("ulid.ulid", function () {
ulid.ulid();
})
.add("wa-ulid.ulid", function () {
try {
waUlid.ulid();
} catch (error) {
console.error(error);
}
})
.on("cycle", function (event) {
console.log(String(event.target));
})
.on("complete", function () {
console.log("ulid comparison complete. Fastest is " + this.filter("fastest").map("name"));
})
.run();
new benchmark.Suite()
.add("ulid.monotonicFactory()", function () {
monotonicUlid();
})
.add("wa-ulid.monotonicFactory()", function () {
monotonicwaUlid();
})
.on("cycle", function (event) {
console.log(String(event.target));
})
.on("complete", function () {
console.log("monotonicFactory() comparison complete. Fastest is " + this.filter("fastest").map("name"));
})
.run();