repositories / pi-ext
pi-ext
bugabingas pi extensions
owned by bugabinga
extensions/terse/__bench__/bench.ts
RawFile outline
import { cpus } from "node:os";
import { injectTerseBlock, TERSE_BLOCK } from "../index.ts";
const prompt = `You are a coding agent. Use tools.
## Available tools
- read: Read files
- bash: Execute shell commands
- edit: Precise replacement
- write: Write files
## Guidelines
${"- Use concise output.\n".repeat(120)}
# Response style
- Abbreviate: DB/auth/config/req/res/fn/impl
- Strip conjunctions, articles
- Arrows: X → Y → Z
- Fragments OK
- No filler, hedging, pleasantries
# Project Context
${"Use exact edits. Prefer rg/fd.\n".repeat(160)}
Current date: 2026-05-04
Current working directory: /repo`;
function oldBuildTerseSystemPrompt(p: string): string {
return `${p}\n\n${TERSE_BLOCK}`;
}
const mode = process.argv[2] === "old" ? "old" : "new";
const threads = cpus().length;
let sink = 0;
function consume(s: string): void {
sink ^=
s.length ^
s.charCodeAt(0) ^
s.charCodeAt(s.length >> 1) ^
s.charCodeAt(s.length - 1);
}
function bench(
name: string,
fn: () => string,
n = 1_000_000,
rounds = 12,
): void {
for (let i = 0; i < 3_000; i++) consume(fn());
for (let r = 0; r < rounds; r++) {
const start = performance.now();
for (let i = 0; i < n; i++) consume(fn());
const ns = ((performance.now() - start) * 1_000_000) / n;
console.log(`Benchmark${name}-${threads}\t${n}\t${ns.toFixed(0)} ns/op`);
}
}
bench(
"TersePrompt",
mode === "old"
? () => oldBuildTerseSystemPrompt(prompt)
: () => injectTerseBlock(prompt),
);
if (sink === 42) console.log("sink", sink);