Skip to content

Instantly share code, notes, and snippets.

@dtinth
Created July 24, 2026 05:22
Show Gist options
  • Select an option

  • Save dtinth/6701f416a5b4e6f581ef087204a043ee to your computer and use it in GitHub Desktop.

Select an option

Save dtinth/6701f416a5b4e6f581ef087204a043ee to your computer and use it in GitHub Desktop.
age-bench
import * as age from "npm:age-encryption@0.3.0";
const durationMs = Number(Deno.args[0] ?? 10) * 1000;
// Warm up (first call pulls in WASM/crypto init, don't count it)
await age.identityToRecipient(await age.generateIdentity());
const start = performance.now();
const deadline = start + durationMs;
let total = 0;
let lastCount = 0;
let lastTime = start;
for (;;) {
const identity = await age.generateIdentity();
await age.identityToRecipient(identity);
total++;
// Check the clock only every so often so timing doesn't dominate
if (total % 256 === 0) {
const now = performance.now();
if (now - lastTime >= 1000) {
const rate = ((total - lastCount) / (now - lastTime)) * 1000;
console.log(`${rate.toFixed(0)} identities/sec (total ${total})`);
lastCount = total;
lastTime = now;
}
if (now >= deadline) break;
}
}
const elapsed = (performance.now() - start) / 1000;
console.log(
`\nTotal: ${total} identities in ${elapsed.toFixed(2)}s ` +
`= ${(total / elapsed).toFixed(0)}/sec ` +
`(${((elapsed / total) * 1000).toFixed(3)} ms each)`,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment