1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-26 17:19:06 -05:00
denoland-deno/ext/timers/benches/timers_ops.rs
Luca Casonato 64a7187238
chore: remove No*Permissions structs (#12316)
These are confusing. They say they are "for users that don't care about
permissions", but that isn't correct. `NoTimersPermissions` disables
permissions instead of enabling them.

I would argue that implementors should decide what permissions they want
themselves, and not take our opinionated permissions struct.
2021-10-04 22:56:24 +02:00

54 lines
1.2 KiB
Rust

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};
use deno_web::BlobStore;
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,
) {
}
}
fn setup() -> Vec<Extension> {
vec![
deno_webidl::init(),
deno_url::init(),
deno_web::init(BlobStore::default(), None),
deno_timers::init::<Permissions>(),
Extension::builder()
.js(vec![
("setup",
Box::new(|| Ok(r#"
const { opNow, setTimeout, handleTimerMacrotask } = globalThis.__bootstrap.timers;
Deno.core.setMacrotaskCallback(handleTimerMacrotask);
"#.to_owned())),
),
])
.state(|state| {
state.put(Permissions{});
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);