1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

bench(deno_common): track readFile 128kb (#11862)

This commit is contained in:
Aaron O'Mullan 2021-08-29 01:05:32 +02:00 committed by GitHub
parent 1f57cd2c0f
commit 8a097410a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 6 deletions

View file

@ -6,13 +6,24 @@ function benchSync(name, n, innerLoop) {
innerLoop(i);
}
const t2 = Date.now();
console.log(benchStats(name, n, t1, t2));
}
async function benchAsync(name, n, innerLoop) {
const t1 = Date.now();
for (let i = 0; i < n; i++) {
await innerLoop(i);
}
const t2 = Date.now();
console.log(benchStats(name, n, t1, t2));
}
function benchStats(name, n, t1, t2) {
const dt = (t2 - t1) / 1e3;
const r = n / dt;
const ns = Math.floor(dt / n * 1e9);
console.log(
`${name}:${" ".repeat(20 - name.length)}\t` +
`n = ${n}, dt = ${dt.toFixed(3)}s, r = ${r.toFixed(0)}/s, t = ${ns}ns/op`,
);
return `${name}:${" ".repeat(20 - name.length)}\t` +
`n = ${n}, dt = ${dt.toFixed(3)}s, r = ${r.toFixed(0)}/s, t = ${ns}ns/op`;
}
function benchUrlParse() {
@ -52,7 +63,15 @@ function benchReadZero() {
Deno.close(file.rid);
}
function main() {
function benchRead128k() {
return benchAsync(
"read_128k",
5e4,
() => Deno.readFile("./cli/bench/fixtures/128k.bin"),
);
}
async function main() {
// v8 builtin that's close to the upper bound non-NOPs
benchDateNow();
// A very lightweight op, that should be highly optimizable
@ -63,5 +82,6 @@ function main() {
// IO ops
benchReadZero();
benchWriteNull();
await benchRead128k();
}
main();
await main();

BIN
cli/bench/fixtures/128k.bin Normal file

Binary file not shown.