2021-04-20 18:15:39 -04:00
|
|
|
use bencher::{benchmark_group, benchmark_main, Bencher};
|
|
|
|
|
|
|
|
use deno_core::v8;
|
2021-04-19 09:42:59 -04:00
|
|
|
use deno_core::JsRuntime;
|
2021-04-28 12:41:50 -04:00
|
|
|
use deno_core::RuntimeOptions;
|
2021-04-19 09:42:59 -04:00
|
|
|
|
2021-04-20 18:15:39 -04:00
|
|
|
fn create_js_runtime() -> JsRuntime {
|
2021-04-28 12:41:50 -04:00
|
|
|
let mut runtime = JsRuntime::new(RuntimeOptions {
|
|
|
|
extensions: vec![deno_url::init()],
|
|
|
|
..Default::default()
|
|
|
|
});
|
2021-04-19 09:42:59 -04:00
|
|
|
|
2021-04-20 18:15:39 -04:00
|
|
|
runtime
|
|
|
|
.execute("setup", "const { URL } = globalThis.__bootstrap.url;")
|
2021-04-19 09:42:59 -04:00
|
|
|
.unwrap();
|
2021-04-20 18:15:39 -04:00
|
|
|
|
|
|
|
runtime
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn bench_runtime_js(b: &mut Bencher, src: &str) {
|
|
|
|
let mut runtime = create_js_runtime();
|
2021-04-28 12:28:46 -04:00
|
|
|
let scope = &mut runtime.handle_scope();
|
2021-04-20 18:15:39 -04:00
|
|
|
let code = v8::String::new(scope, src).unwrap();
|
|
|
|
let script = v8::Script::compile(scope, code, None).unwrap();
|
|
|
|
b.iter(|| {
|
|
|
|
script.run(scope).unwrap();
|
|
|
|
});
|
2021-04-19 09:42:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn bench_url_parse(b: &mut Bencher) {
|
2021-04-20 18:15:39 -04:00
|
|
|
bench_runtime_js(b, r#"new URL(`http://www.google.com/`);"#);
|
2021-04-19 09:42:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
benchmark_group!(benches, bench_url_parse,);
|
2021-04-20 18:15:39 -04:00
|
|
|
benchmark_main!(benches);
|