From 34328335743a377a701c5b812ab725c34ecc29c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 21 Apr 2021 00:15:39 +0200 Subject: chore: release crates (#10269) * Revert "tooling(bench_util): benching and profiling utilities (#10223)" This reverts commit 733a00030582375c43fa156e978f25df6ecc9e9a. * Upgrade notify --- op_crates/url/Cargo.toml | 6 ++--- op_crates/url/benches/url_ops.rs | 53 +++++++++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 15 deletions(-) (limited to 'op_crates/url') diff --git a/op_crates/url/Cargo.toml b/op_crates/url/Cargo.toml index a67b59d7f..44394f6a5 100644 --- a/op_crates/url/Cargo.toml +++ b/op_crates/url/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_url" -version = "0.3.0" +version = "0.4.0" edition = "2018" description = "URL API implementation for Deno" authors = ["the Deno authors"] @@ -14,13 +14,13 @@ repository = "https://github.com/denoland/deno" path = "lib.rs" [dependencies] -deno_core = { version = "0.84.0", path = "../../core" } +deno_core = { version = "0.85.0", path = "../../core" } idna = "0.2.2" percent-encoding = "2.1.0" serde = { version = "1.0.125", features = ["derive"] } [dev-dependencies] -bench_util = { version = "0.0.0", path = "../../bench_util" } +bencher = "0.1" [[bench]] name = "url_ops" diff --git a/op_crates/url/benches/url_ops.rs b/op_crates/url/benches/url_ops.rs index fc2742fbd..17029b9c6 100644 --- a/op_crates/url/benches/url_ops.rs +++ b/op_crates/url/benches/url_ops.rs @@ -1,29 +1,58 @@ +use bencher::{benchmark_group, benchmark_main, Bencher}; + use deno_core::op_sync; +use deno_core::v8; use deno_core::JsRuntime; -use bench_util::bench_js_sync; -use bench_util::bench_or_profile; -use bench_util::bencher::{benchmark_group, Bencher}; - -fn setup(rt: &mut JsRuntime) { - rt.register_op("op_url_parse", op_sync(deno_url::op_url_parse)); - rt.register_op( +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), ); - rt.register_op( + runtime.register_op( "op_url_stringify_search_params", op_sync(deno_url::op_url_stringify_search_params), ); - deno_url::init(rt); - rt.execute("setup", "const { URL } = globalThis.__bootstrap.url;") + runtime + .execute( + "bootstrap", + "globalThis.__bootstrap = (globalThis.__bootstrap || {});", + ) + .unwrap(); + deno_url::init(&mut runtime); + runtime + .execute( + "init", + r#" + Deno.core.ops(); + Deno.core.registerErrorClass('Error', Error); + "#, + ) + .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 context = runtime.global_context(); + let scope = &mut v8::HandleScope::with_context(runtime.v8_isolate(), context); + 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_js_sync(b, r#"new URL(`http://www.google.com/${i}`);"#, setup); + bench_runtime_js(b, r#"new URL(`http://www.google.com/`);"#); } benchmark_group!(benches, bench_url_parse,); -bench_or_profile!(benches); +benchmark_main!(benches); -- cgit v1.2.3