1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-06 06:19:05 -05:00

bench(timers_ops): op_now() & setTimeout() (#10744)

This commit is contained in:
Aaron O'Mullan 2021-05-22 22:52:05 +02:00 committed by GitHub
parent b88fcef26b
commit 8fd951b200
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 0 deletions
Cargo.lock
extensions/timers

1
Cargo.lock generated
View file

@ -738,6 +738,7 @@ dependencies = [
name = "deno_timers"
version = "0.5.0"
dependencies = [
"deno_bench_util",
"deno_core",
"tokio",
]

View file

@ -16,3 +16,10 @@ path = "lib.rs"
[dependencies]
deno_core = { version = "0.88.0", path = "../../core" }
tokio = { version = "1.6.0", features = ["full"] }
[dev-dependencies]
deno_bench_util = { version = "0.1.0", path = "../../bench_util" }
[[bench]]
name = "timers_ops"
harness = false

View file

@ -0,0 +1,34 @@
use deno_core::Extension;
use deno_bench_util::bench_or_profile;
use deno_bench_util::bencher::{benchmark_group, Bencher};
use deno_bench_util::{bench_js_async, bench_js_sync};
fn setup() -> Vec<Extension> {
vec![
deno_timers::init::<deno_timers::NoTimersPermission>(),
Extension::builder()
.js(vec![
("setup", r#"
const { opNow, setTimeout, handleTimerMacrotask } = globalThis.__bootstrap.timers;
Deno.core.setMacrotaskCallback(handleTimerMacrotask);
"#),
])
.state(|state| {
state.put(deno_timers::NoTimersPermission{});
Ok(())
})
.build()
]
}
fn bench_op_now(b: &mut Bencher) {
bench_js_sync(b, r#"opNow();"#, setup);
}
fn bench_set_timeout(b: &mut Bencher) {
bench_js_async(b, r#"setTimeout(() => {}, 0);"#, setup);
}
benchmark_group!(benches, bench_op_now, bench_set_timeout,);
bench_or_profile!(benches);