2023-01-13 02:51:32 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2021-05-22 16:52:05 -04:00
|
|
|
|
2022-08-28 02:51:49 -04:00
|
|
|
use deno_bench_util::bench_js_async;
|
2021-05-22 16:52:05 -04:00
|
|
|
use deno_bench_util::bench_or_profile;
|
2023-01-14 23:18:58 -05:00
|
|
|
use deno_bench_util::bencher::benchmark_group;
|
|
|
|
use deno_bench_util::bencher::Bencher;
|
2023-01-13 02:51:32 -05:00
|
|
|
use deno_core::Extension;
|
2021-07-05 09:34:37 -04:00
|
|
|
use deno_web::BlobStore;
|
2021-05-22 16:52:05 -04:00
|
|
|
|
2021-10-04 16:56:24 -04:00
|
|
|
struct Permissions;
|
|
|
|
|
2022-02-15 06:17:30 -05:00
|
|
|
impl deno_web::TimersPermission for Permissions {
|
2021-10-04 16:56:24 -04:00
|
|
|
fn allow_hrtime(&mut self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
fn check_unstable(
|
|
|
|
&self,
|
|
|
|
_state: &deno_core::OpState,
|
|
|
|
_api_name: &'static str,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-22 16:52:05 -04:00
|
|
|
fn setup() -> Vec<Extension> {
|
|
|
|
vec![
|
2021-07-03 15:32:28 -04:00
|
|
|
deno_webidl::init(),
|
|
|
|
deno_url::init(),
|
2023-01-08 17:48:46 -05:00
|
|
|
deno_console::init(),
|
2022-02-15 06:17:30 -05:00
|
|
|
deno_web::init::<Permissions>(BlobStore::default(), None),
|
2023-01-08 17:48:46 -05:00
|
|
|
Extension::builder("bench_setup")
|
2023-02-07 14:22:46 -05:00
|
|
|
.esm(vec![
|
|
|
|
("internal:setup", r#"
|
|
|
|
import { setTimeout, handleTimerMacrotask } from "internal:ext/web/02_timers.js";
|
|
|
|
globalThis.setTimeout = setTimeout;
|
2022-05-15 07:27:56 -04:00
|
|
|
Deno.core.setMacrotaskCallback(handleTimerMacrotask);
|
|
|
|
"#),
|
2021-05-22 16:52:05 -04:00
|
|
|
])
|
|
|
|
.state(|state| {
|
2021-10-04 16:56:24 -04:00
|
|
|
state.put(Permissions{});
|
2021-05-22 16:52:05 -04:00
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
.build()
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bench_set_timeout(b: &mut Bencher) {
|
|
|
|
bench_js_async(b, r#"setTimeout(() => {}, 0);"#, setup);
|
|
|
|
}
|
|
|
|
|
2022-08-28 02:51:49 -04:00
|
|
|
benchmark_group!(benches, bench_set_timeout,);
|
2021-05-22 16:52:05 -04:00
|
|
|
bench_or_profile!(benches);
|