mirror of
https://github.com/denoland/deno.git
synced 2025-01-08 07:08:27 -05:00
bench(timers_ops): op_now() & setTimeout() (#10744)
This commit is contained in:
parent
b88fcef26b
commit
8fd951b200
3 changed files with 42 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -738,6 +738,7 @@ dependencies = [
|
||||||
name = "deno_timers"
|
name = "deno_timers"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"deno_bench_util",
|
||||||
"deno_core",
|
"deno_core",
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
|
@ -16,3 +16,10 @@ path = "lib.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
deno_core = { version = "0.88.0", path = "../../core" }
|
deno_core = { version = "0.88.0", path = "../../core" }
|
||||||
tokio = { version = "1.6.0", features = ["full"] }
|
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
|
||||||
|
|
34
extensions/timers/benches/timers_ops.rs
Normal file
34
extensions/timers/benches/timers_ops.rs
Normal 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);
|
Loading…
Reference in a new issue