2021-05-22 16:52:05 -04:00
|
|
|
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};
|
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;
|
|
|
|
|
|
|
|
impl deno_timers::TimersPermission for Permissions {
|
|
|
|
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(),
|
2021-07-05 09:34:37 -04:00
|
|
|
deno_web::init(BlobStore::default(), None),
|
2021-10-04 16:56:24 -04:00
|
|
|
deno_timers::init::<Permissions>(),
|
2021-05-22 16:52:05 -04:00
|
|
|
Extension::builder()
|
|
|
|
.js(vec![
|
2021-05-29 10:20:52 -04:00
|
|
|
("setup",
|
|
|
|
Box::new(|| Ok(r#"
|
|
|
|
const { opNow, setTimeout, handleTimerMacrotask } = globalThis.__bootstrap.timers;
|
|
|
|
Deno.core.setMacrotaskCallback(handleTimerMacrotask);
|
|
|
|
"#.to_owned())),
|
|
|
|
),
|
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_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);
|