-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-chart.js
More file actions
executable file
·79 lines (64 loc) · 2.15 KB
/
generate-chart.js
File metadata and controls
executable file
·79 lines (64 loc) · 2.15 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
#!/usr/bin/env node
/**
* Wunderbar Chart Generator
*
* Generates horizontal bar chart visualization from benchmark-results.json
* using wunderbar (https://github.com/gribnoysup/wunderbar).
*
* This script is automatically called by benchmark.sh to create charts
* with precise partial block characters (▏▎▍▌▋▊▉█).
*
* Usage:
* node generate-chart.js
*
* Requirements:
* - benchmark-results.json must exist (generated by hyperfine)
* - @gribnoysup/wunderbar must be installed
*/
const fs = require('fs');
const wunderbar = require('@gribnoysup/wunderbar');
// Read benchmark results
const RESULTS_FILE = 'benchmark-results.json';
if (!fs.existsSync(RESULTS_FILE)) {
console.error(`Error: ${RESULTS_FILE} not found. Run ./benchmark.sh first.`);
process.exit(1);
}
const benchmarkData = JSON.parse(fs.readFileSync(RESULTS_FILE, 'utf8'));
// Sort by mean time (fastest first) and extract data
const results = benchmarkData.results
.sort((a, b) => a.mean - b.mean)
.map(result => ({
name: result.command,
mean: result.mean,
meanFormatted: (result.mean).toFixed(2),
}));
// Get fastest time for relative calculation
const fastestTime = results[0].mean;
// Prepare data for wunderbar
const data = results.map(r => ({
value: r.mean,
label: r.name,
}));
// Calculate max value (round up to next second for nice scale)
const maxValue = Math.ceil(results[results.length - 1].mean);
const { chart, scale } = wunderbar(data, {
min: 0,
max: maxValue,
length: 50,
format: '0.00',
});
console.log('🚀 Generation Time Comparison (lower is better)\n');
// Combine labels with bars manually
const chartLines = chart.split('\n').filter(line => line.trim());
chartLines.forEach((line, idx) => {
if (idx < results.length) {
const result = results[idx];
const relative = (result.mean / fastestTime).toFixed(1);
const relativeText = idx === 0 ? '1.0x' : `${relative}x`;
const mean = `${result.meanFormatted}s`
// Format label with padding
const label = `${result.name.padEnd(15)} ${mean.padEnd(6)} `;
console.log(`${label} ${line} ${relativeText}`);
}
});
console.log(` ${scale}`);