-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.ts
More file actions
58 lines (48 loc) · 1.78 KB
/
Copy pathbenchmark.ts
File metadata and controls
58 lines (48 loc) · 1.78 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 { execSync } from 'child_process';
import fs from 'fs';
import path from 'path';
const ROOT = path.resolve(__dirname, '..');
const BENCH_DIR = path.join(ROOT, 'temp_bench');
const OUT_DIR = path.join(BENCH_DIR, 'out');
// Ensure clean state
if (fs.existsSync(BENCH_DIR)) {
fs.rmSync(BENCH_DIR, { recursive: true, force: true });
}
fs.mkdirSync(BENCH_DIR);
const SAMPLE_IMG = path.join(BENCH_DIR, 'sample.png');
// Create a 1x1 pixel PNG
console.log('Creating sample file...');
const buffer = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=', 'base64');
fs.writeFileSync(SAMPLE_IMG, buffer);
try {
console.log('Running Benchmark...');
const start = Date.now();
// Run CLI
// We assume 'apo' is linked or we run via node packages/node/bin/apo.js
const CLI = path.join(ROOT, 'packages/node/bin/apo.js');
// Note: Use *.png glob
const cmd = `node ${CLI} build "${BENCH_DIR}/*.png" --out ${OUT_DIR} --json --clean`;
const output = execSync(cmd).toString();
const duration = Date.now() - start;
console.log('Benchmark Output:', output);
try {
const result = JSON.parse(output);
const report = {
durationMs: duration,
imagesProcessed: result.totalFiles,
totalSavedBytes: result.totalSavedBytes,
imagesPerSecond: (result.totalFiles / (duration / 1000)).toFixed(2)
};
console.log('BENCHMARK REPORT:', JSON.stringify(report, null, 2));
} catch {
console.error('Failed to parse benchmark JSON output');
}
} catch (e) {
console.error('Benchmark failed:', e);
process.exit(1);
} finally {
// Cleanup
if (fs.existsSync(BENCH_DIR)) {
fs.rmSync(BENCH_DIR, { recursive: true, force: true });
}
}