diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-08-29 01:05:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-29 01:05:32 +0200 |
commit | 8a097410a8df3195681305818035ab7dde41452b (patch) | |
tree | 49f2da5c34933ef167e611105ceedb680cccd0cd /cli/bench/deno_common.js | |
parent | 1f57cd2c0f0d7d9020fc2667bb7b1af54822ceb2 (diff) |
bench(deno_common): track readFile 128kb (#11862)
Diffstat (limited to 'cli/bench/deno_common.js')
-rw-r--r-- | cli/bench/deno_common.js | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/cli/bench/deno_common.js b/cli/bench/deno_common.js index 42f447e3c..1e3034c27 100644 --- a/cli/bench/deno_common.js +++ b/cli/bench/deno_common.js @@ -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(); |