From f2ac7ff23a2ae4925f4ca32ffd61c923c481ef4e Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Sun, 10 Oct 2021 16:36:55 +0200 Subject: [PATCH] bench(deno_common): track void ops (#12389) To track overhead through the entire CLI opcall stack (metrics included, etc...) --- cli/bench/deno_common.js | 27 +++++++++++++++++++++++++++ core/ops_builtin.rs | 4 ++++ 2 files changed, 31 insertions(+) diff --git a/cli/bench/deno_common.js b/cli/bench/deno_common.js index cc54b10367..73a2f62c5f 100644 --- a/cli/bench/deno_common.js +++ b/cli/bench/deno_common.js @@ -18,6 +18,17 @@ async function benchAsync(name, n, innerLoop) { console.log(benchStats(name, n, t1, t2)); } +// Parallel version benchAsync +async function benchAsyncP(name, n, p, innerLoop) { + const range = new Array(p).fill(null); + const t1 = Date.now(); + for (let i = 0; i < n / p; i++) { + await Promise.all(range.map(() => innerLoop())); + } + 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; @@ -75,9 +86,25 @@ function benchRequestNew() { return benchSync("request_new", 5e5, () => new Request("https://deno.land")); } +function benchOpVoidSync() { + return benchSync("op_void_sync", 1e7, () => Deno.core.opSync("op_void_sync")); +} + +function benchOpVoidAsync() { + return benchAsyncP( + "op_void_async", + 1e6, + 1e3, + () => Deno.core.opAsync("op_void_async"), + ); +} + async function main() { // v8 builtin that's close to the upper bound non-NOPs benchDateNow(); + // Void ops measure op-overhead + benchOpVoidSync(); + await benchOpVoidAsync(); // A very lightweight op, that should be highly optimizable benchPerfNow(); // A common "language feature", that should be fast diff --git a/core/ops_builtin.rs b/core/ops_builtin.rs index bb04cddf44..83f2e504a2 100644 --- a/core/ops_builtin.rs +++ b/core/ops_builtin.rs @@ -3,6 +3,8 @@ use crate::error::AnyError; use crate::include_js_files; use crate::op_sync; use crate::resources::ResourceId; +use crate::void_op_async; +use crate::void_op_sync; use crate::Extension; use crate::OpState; use crate::Resource; @@ -30,6 +32,8 @@ pub(crate) fn init_builtins() -> Extension { "op_wasm_streaming_set_url", op_sync(op_wasm_streaming_set_url), ), + ("op_void_sync", void_op_sync()), + ("op_void_async", void_op_async()), ]) .build() }