Repository navigation
Expand file tree
/
Copy pathissue87-prototype-benchmark.cjs
More file actions
97 lines (84 loc) · 3.2 KB
/
Copy pathissue87-prototype-benchmark.cjs
File metadata and controls
97 lines (84 loc) · 3.2 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
'use strict';
const assert = require('node:assert/strict');
const fs = require('node:fs/promises');
const path = require('node:path');
const { performance } = require('node:perf_hooks');
const {
createClaudePrototypeIndex,
prototypeSnapshot,
rebuildClaudePrototypeIndex,
updateClaudePrototypeIndex,
} = require('./out/claudeIncrementalPrototype.js');
function ms(start) {
return performance.now() - start;
}
async function jsonlFiles(directory) {
const output = [];
const walk = async (current) => {
const entries = await fs.readdir(current, { withFileTypes: true });
for (const entry of entries) {
const absolute = path.join(current, entry.name);
if (entry.isDirectory()) await walk(absolute);
else if (entry.isFile() && entry.name.endsWith('.jsonl')) output.push(absolute);
}
};
await walk(path.join(directory, 'projects'));
return output.sort();
}
function line(id, input, output) {
return JSON.stringify({
type: 'assistant',
timestamp: '2026-08-21T08:00:00.000Z',
requestId: `request-${id}`,
cwd: '/benchmark/project-0',
gitBranch: 'benchmark-tail',
workflowId: 'wf-benchmark',
message: {
id: `message-${id}`,
model: 'claude-sonnet-4-5',
content: [{ type: 'text', text: `safe-${id}` }],
usage: {
input_tokens: input,
output_tokens: output,
cache_creation_input_tokens: 2,
cache_read_input_tokens: 3,
},
},
}) + '\n';
}
async function assertExact(root, index) {
const rebuilt = await rebuildClaudePrototypeIndex(root);
assert.deepEqual(
prototypeSnapshot(index, Date.parse('2026-08-21T12:00:00.000Z')),
prototypeSnapshot(rebuilt.index, Date.parse('2026-08-21T12:00:00.000Z')),
);
}
async function main() {
const root = path.resolve(process.argv[2]);
const files = await jsonlFiles(root);
if (files.length === 0) throw new Error('prototype benchmark has no JSONL files');
let start = performance.now();
let current = await updateClaudePrototypeIndex(createClaudePrototypeIndex(), root);
const cold = { wallMs: ms(start), diagnostics: current.diagnostics };
await assertExact(root, current.index);
start = performance.now();
current = await updateClaudePrototypeIndex(current.index, root);
const unchanged = { wallMs: ms(start), diagnostics: current.diagnostics };
const appended = line('prototype-append', 17, 5);
await fs.appendFile(files[0], appended, 'utf8');
start = performance.now();
current = await updateClaudePrototypeIndex(current.index, root);
const append = { wallMs: ms(start), diagnostics: current.diagnostics, expectedBytes: Buffer.byteLength(appended) };
await assertExact(root, current.index);
const truncated = line('prototype-truncate', 9, 2);
await fs.writeFile(files[0], truncated, 'utf8');
start = performance.now();
current = await updateClaudePrototypeIndex(current.index, root);
const truncate = { wallMs: ms(start), diagnostics: current.diagnostics, expectedBytes: Buffer.byteLength(truncated) };
await assertExact(root, current.index);
process.stdout.write(JSON.stringify({ cold, unchanged, append, truncate }) + '\n');
}
main().catch((error) => {
process.stderr.write(`${error.stack || error}\n`);
process.exitCode = 1;
});