-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark-compiler.ts
More file actions
58 lines (48 loc) · 1.8 KB
/
benchmark-compiler.ts
File metadata and controls
58 lines (48 loc) · 1.8 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 { compileHypernoteToContent } from "./src/lib/compiler";
import chessMd from "./examples/chess.md";
import counterMd from "./examples/counter.md";
import basicHelloMd from "./examples/basic-hello.md";
import clientMd from "./examples/client.md";
function benchmark(name: string, markdown: string) {
console.log(`\n=== Benchmarking ${name} ===`);
const start = performance.now();
const result = compileHypernoteToContent(markdown);
const end = performance.now();
const time = end - start;
const size = JSON.stringify(result).length;
console.log(`Time: ${time.toFixed(2)}ms`);
console.log(`Output size: ${size} chars`);
console.log(`Elements: ${result.elements?.length || 0}`);
// Count total elements recursively
let totalElements = 0;
function countElements(elements: any[]) {
if (!elements) return;
totalElements += elements.length;
for (const el of elements) {
if (el.elements) countElements(el.elements);
}
}
countElements(result.elements || []);
console.log(`Total elements (nested): ${totalElements}`);
return { name, time, size, elements: totalElements };
}
console.log("Starting Hypernote Compiler Benchmarks");
console.log("======================================");
const results = [
benchmark("basic-hello", basicHelloMd),
benchmark("counter", counterMd),
benchmark("client", clientMd),
benchmark("chess", chessMd),
];
console.log("\n=== Summary ===");
console.log("Name\t\tTime (ms)\tSize (chars)\tElements");
for (const r of results) {
console.log(`${r.name}\t${r.time.toFixed(2)}\t\t${r.size}\t\t${r.elements}`);
}
// Calculate relative slowdown
const baseTime = results[0].time;
console.log("\n=== Relative Slowdown ===");
for (const r of results) {
const slowdown = r.time / baseTime;
console.log(`${r.name}: ${slowdown.toFixed(1)}x`);
}