diff options
-rw-r--r-- | cli/bench/async_ops_deferred.js | 20 | ||||
-rw-r--r-- | core/ops_builtin.rs | 4 |
2 files changed, 24 insertions, 0 deletions
diff --git a/cli/bench/async_ops_deferred.js b/cli/bench/async_ops_deferred.js new file mode 100644 index 000000000..7a816cf95 --- /dev/null +++ b/cli/bench/async_ops_deferred.js @@ -0,0 +1,20 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +const queueMicrotask = globalThis.queueMicrotask || process.nextTick; +let [total, count] = typeof Deno !== "undefined" + ? Deno.args + : [process.argv[2], process.argv[3]]; + +total = total ? parseInt(total, 0) : 50; +count = count ? parseInt(count, 10) : 1000000; + +async function bench(fun) { + const start = Date.now(); + for (let i = 0; i < count; i++) await fun(); + const elapsed = Date.now() - start; + const rate = Math.floor(count / (elapsed / 1000)); + console.log(`time ${elapsed} ms rate ${rate}`); + if (--total) queueMicrotask(() => bench(fun)); +} + +const core = Deno[Deno.internal].core; +bench(() => core.opAsync("op_void_async_deferred")); diff --git a/core/ops_builtin.rs b/core/ops_builtin.rs index 2786299bf..ea85b4f00 100644 --- a/core/ops_builtin.rs +++ b/core/ops_builtin.rs @@ -28,6 +28,7 @@ crate::extension!( op_wasm_streaming_set_url, op_void_sync, op_void_async, + op_void_async_deferred, op_add, // TODO(@AaronO): track IO metrics for builtin streams op_read, @@ -99,6 +100,9 @@ pub fn op_void_sync() {} #[op] pub async fn op_void_async() {} +#[op(deferred)] +pub async fn op_void_async_deferred() {} + /// Remove a resource from the resource table. #[op] pub fn op_close( |