0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-06 22:45:03 -05:00
denoland-deno/op_crates/url/benches/url_ops.rs
Bartek Iwańczuk b28f9445aa
refactor(core): simplify module loading code (#10385)
General cleanup of module loading code, tried to reduce indentation in various methods
on "JsRuntime" to improve readability.

Added "JsRuntime::handle_scope" helper function, which returns a "v8::HandleScope".
This was done to reduce a code pattern that happens all over the "deno_core".

Additionally if event loop hangs during loading of dynamic modules a list of
currently pending dynamic imports is printed.
2021-04-28 18:28:46 +02:00

49 lines
1.3 KiB
Rust

use bencher::{benchmark_group, benchmark_main, Bencher};
use deno_core::op_sync;
use deno_core::v8;
use deno_core::JsRuntime;
fn create_js_runtime() -> JsRuntime {
let mut runtime = JsRuntime::new(Default::default());
runtime.register_op("op_url_parse", op_sync(deno_url::op_url_parse));
runtime.register_op(
"op_url_parse_search_params",
op_sync(deno_url::op_url_parse_search_params),
);
runtime.register_op(
"op_url_stringify_search_params",
op_sync(deno_url::op_url_stringify_search_params),
);
runtime.sync_ops_cache();
runtime
.execute(
"bootstrap",
"globalThis.__bootstrap = (globalThis.__bootstrap || {});",
)
.unwrap();
deno_url::init(&mut runtime);
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);