-
-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathbench.ts
More file actions
36 lines (31 loc) · 992 Bytes
/
bench.ts
File metadata and controls
36 lines (31 loc) · 992 Bytes
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
// JSON parse + stringify polyglot benchmark — Perry / TypeScript / Bun / Node.
// 10k records, ~1 MB blob, 50 iterations, best-of-5 reporting.
// IDENTICAL workload across every language in this directory.
const items: any[] = [];
for (let i = 0; i < 10000; i++) {
items.push({
id: i,
name: "item_" + i,
value: i * 3.14159,
tags: ["tag_" + (i % 10), "tag_" + (i % 5)],
nested: { x: i, y: i * 2 }
});
}
const blob = JSON.stringify(items);
// Warmup — keeps JIT-y runtimes from charging us startup.
for (let i = 0; i < 3; i++) {
const parsed = JSON.parse(blob);
JSON.stringify(parsed);
}
const ITERATIONS = 50;
const start = Date.now();
let checksum = 0;
for (let iter = 0; iter < ITERATIONS; iter++) {
const parsed = JSON.parse(blob);
checksum += parsed.length;
const reStringified = JSON.stringify(parsed);
checksum += reStringified.length;
}
const elapsed = Date.now() - start;
console.log("ms:" + elapsed);
console.log("checksum:" + checksum);