-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench.ts
More file actions
79 lines (59 loc) · 2.03 KB
/
bench.ts
File metadata and controls
79 lines (59 loc) · 2.03 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// deno-lint-ignore-file no-import-prefix no-unversioned-import
import { decodeCBOR, encodeCBOR } from "@char/cbor";
import * as cborx from "npm:cbor-x";
// import * as cbor2 from "npm:cbor2";
import * as currCBOR from "jsr:@char/cbor";
const BATCH_SIZE = 64;
// dreamlab network snapshot packet
const snapshotData = await Deno.readFile("./_test/snapshot.cbor");
const snapshot = currCBOR.decodeCBOR(snapshotData);
import { assertEquals } from "jsr:@std/assert";
assertEquals(decodeCBOR(snapshotData), snapshot);
/* Deno.bench("cbor2", { group: "encode" }, () => {
const results = new Array(BATCH_SIZE);
for (let i = 0; i < results.length; i++) {
results[i] = cbor2.encode(snapshot);
}
}); */
Deno.bench("@char/cbor", { group: "encode" }, () => {
const results = new Array(BATCH_SIZE);
for (let i = 0; i < results.length; i++) {
results[i] = encodeCBOR(snapshot);
}
});
Deno.bench("jsr @char/cbor", { group: "encode" }, () => {
const results = new Array(BATCH_SIZE);
for (let i = 0; i < results.length; i++) {
results[i] = currCBOR.encodeCBOR(snapshot);
}
});
/* Deno.bench("cbor-x", { group: "encode" }, () => {
const results = new Array(BATCH_SIZE);
for (let i = 0; i < results.length; i++) {
results[i] = cborx.encode(snapshot);
}
}); */
/* Deno.bench("cbor2", { group: "decode" }, () => {
const results = new Array(BATCH_SIZE);
for (let i = 0; i < results.length; i++) {
results[i] = cbor2.decode(snapshotData);
}
}); */
Deno.bench("@char/cbor", { group: "decode" }, () => {
const results = new Array(BATCH_SIZE);
for (let i = 0; i < results.length; i++) {
results[i] = decodeCBOR(snapshotData);
}
});
Deno.bench("jsr @char/cbor", { group: "decode" }, () => {
const results = new Array(BATCH_SIZE);
for (let i = 0; i < results.length; i++) {
results[i] = currCBOR.decodeCBOR(snapshotData);
}
});
Deno.bench("cbor-x", { group: "decode" }, () => {
const results = new Array(BATCH_SIZE);
for (let i = 0; i < results.length; i++) {
results[i] = cborx.decode(snapshotData);
}
});