summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-05-22 22:52:05 +0200
committerGitHub <noreply@github.com>2021-05-22 16:52:05 -0400
commit8fd951b2002ed5a2af309672832e491062657537 (patch)
tree394d6dd03fef730f7e4258b307b0f897286248ad
parentb88fcef26be6f45472c2c6891212deae3192897c (diff)
bench(timers_ops): op_now() & setTimeout() (#10744)
-rw-r--r--Cargo.lock1
-rw-r--r--extensions/timers/Cargo.toml7
-rw-r--r--extensions/timers/benches/timers_ops.rs34
3 files changed, 42 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 70eaa1004..80eb45ffb 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -738,6 +738,7 @@ dependencies = [
name = "deno_timers"
version = "0.5.0"
dependencies = [
+ "deno_bench_util",
"deno_core",
"tokio",
]
diff --git a/extensions/timers/Cargo.toml b/extensions/timers/Cargo.toml
index d9bb23614..d16bfa9a0 100644
--- a/extensions/timers/Cargo.toml
+++ b/extensions/timers/Cargo.toml
@@ -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
diff --git a/extensions/timers/benches/timers_ops.rs b/extensions/timers/benches/timers_ops.rs
new file mode 100644
index 000000000..18ef10336
--- /dev/null
+++ b/extensions/timers/benches/timers_ops.rs
@@ -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);