0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-31 09:14:20 -04:00
denoland-deno/op_crates/url/benches/url_ops.rs
Aaron O'Mullan 0260b488fb
core: introduce extensions (#9800)
Extensions allow declarative extensions to "JsRuntime" (ops, state, JS or middleware).

This allows for:
- `op_crates` to be plug-and-play & self-contained, reducing complexity leaked to consumers
- op middleware (like metrics_op) to be opt-in and for new middleware (unstable, tracing,...)
- `MainWorker` and `WebWorker` to be composable, allowing users to extend workers with their ops whilst benefiting from the other infrastructure (inspector, etc...)

In short extensions improve deno's modularity, reducing complexity and leaky abstractions for embedders and the internal codebase.
2021-04-28 18:41:50 +02:00

45 lines
1.1 KiB
Rust

use bencher::{benchmark_group, benchmark_main, Bencher};
use deno_core::v8;
use deno_core::JsRuntime;
use deno_core::RuntimeOptions;
fn create_js_runtime() -> JsRuntime {
let mut runtime = JsRuntime::new(RuntimeOptions {
extensions: vec![deno_url::init()],
..Default::default()
});
runtime
.execute(
"bootstrap",
"globalThis.__bootstrap = (globalThis.__bootstrap || {});",
)
.unwrap();
runtime.init_extension_js().unwrap();
runtime.init_extension_ops().unwrap();
runtime
.execute("setup", "const { URL } = globalThis.__bootstrap.url;")
.unwrap();
runtime
}
pub fn bench_runtime_js(b: &mut Bencher, src: &str) {
let mut runtime = create_js_runtime();
let scope = &mut runtime.handle_scope();
let code = v8::String::new(scope, src).unwrap();
let script = v8::Script::compile(scope, code, None).unwrap();
b.iter(|| {
script.run(scope).unwrap();
});
}
fn bench_url_parse(b: &mut Bencher) {
bench_runtime_js(b, r#"new URL(`http://www.google.com/`);"#);
}
benchmark_group!(benches, bench_url_parse,);
benchmark_main!(benches);