1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

bench(deno_common): track void ops (#12389)

To track overhead through the entire CLI opcall stack (metrics included, etc...)
This commit is contained in:
Aaron O'Mullan 2021-10-10 16:36:55 +02:00 committed by GitHub
parent 5edd277161
commit f2ac7ff23a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View file

@ -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

View file

@ -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()
}