mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
tooling: re-enable bench_util (#10674)
This commit is contained in:
parent
df7639c096
commit
24da0aa37d
7 changed files with 79 additions and 129 deletions
21
Cargo.lock
generated
21
Cargo.lock
generated
|
@ -193,15 +193,6 @@ version = "0.13.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bench_util"
|
|
||||||
version = "0.0.0"
|
|
||||||
dependencies = [
|
|
||||||
"bencher",
|
|
||||||
"deno_core",
|
|
||||||
"tokio",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bencher"
|
name = "bencher"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
|
@ -591,6 +582,15 @@ dependencies = [
|
||||||
"winres",
|
"winres",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "deno_bench_util"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"bencher",
|
||||||
|
"deno_core",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deno_console"
|
name = "deno_console"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
|
@ -603,7 +603,6 @@ name = "deno_core"
|
||||||
version = "0.88.0"
|
version = "0.88.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bencher",
|
|
||||||
"futures",
|
"futures",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
@ -747,7 +746,7 @@ dependencies = [
|
||||||
name = "deno_url"
|
name = "deno_url"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bencher",
|
"deno_bench_util",
|
||||||
"deno_core",
|
"deno_core",
|
||||||
"idna",
|
"idna",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||||
[package]
|
[package]
|
||||||
name = "bench_util"
|
name = "deno_bench_util"
|
||||||
version = "0.0.0"
|
version = "0.1.0"
|
||||||
authors = ["the Deno authors"]
|
authors = ["the Deno authors"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Bench and profiling utilities for deno crates"
|
description = "Bench and profiling utilities for deno crates"
|
||||||
|
@ -16,3 +16,7 @@ publish = false
|
||||||
bencher = "0.1"
|
bencher = "0.1"
|
||||||
deno_core = { version = "0.88.0", path = "../core" }
|
deno_core = { version = "0.88.0", path = "../core" }
|
||||||
tokio = { version = "1.6.0", features = ["full"] }
|
tokio = { version = "1.6.0", features = ["full"] }
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "op_baseline"
|
||||||
|
harness = false
|
||||||
|
|
47
bench_util/benches/op_baseline.rs
Normal file
47
bench_util/benches/op_baseline.rs
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
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_core::error::AnyError;
|
||||||
|
use deno_core::op_async;
|
||||||
|
use deno_core::op_sync;
|
||||||
|
use deno_core::serialize_op_result;
|
||||||
|
use deno_core::JsRuntime;
|
||||||
|
use deno_core::Op;
|
||||||
|
use deno_core::OpState;
|
||||||
|
|
||||||
|
use std::cell::RefCell;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
fn setup(runtime: &mut JsRuntime) {
|
||||||
|
runtime.register_op("pi_json", op_sync(|_, _: (), _: ()| Ok(314159)));
|
||||||
|
runtime.register_op("pi_async", op_async(op_pi_async));
|
||||||
|
runtime.register_op("nop", |state, _| {
|
||||||
|
Op::Sync(serialize_op_result(Ok(9), state))
|
||||||
|
});
|
||||||
|
runtime.sync_ops_cache();
|
||||||
|
}
|
||||||
|
|
||||||
|
// this is a function since async closures aren't stable
|
||||||
|
async fn op_pi_async(
|
||||||
|
_: Rc<RefCell<OpState>>,
|
||||||
|
_: (),
|
||||||
|
_: (),
|
||||||
|
) -> Result<i64, AnyError> {
|
||||||
|
Ok(314159)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bench_op_pi_json(b: &mut Bencher) {
|
||||||
|
bench_js_sync(b, r#"Deno.core.opSync("pi_json", null);"#, setup);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bench_op_nop(b: &mut Bencher) {
|
||||||
|
bench_js_sync(b, r#"Deno.core.opSync("nop", null, null, null);"#, setup);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bench_op_async(b: &mut Bencher) {
|
||||||
|
bench_js_async(b, r#"Deno.core.opAsync("pi_async", null);"#, setup);
|
||||||
|
}
|
||||||
|
|
||||||
|
benchmark_group!(benches, bench_op_pi_json, bench_op_nop, bench_op_async);
|
||||||
|
bench_or_profile!(benches);
|
|
@ -34,8 +34,3 @@ path = "examples/http_bench_json_ops.rs"
|
||||||
# These dependencies are only used for the 'http_bench_*_ops' examples.
|
# These dependencies are only used for the 'http_bench_*_ops' examples.
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio = { version = "1.6.0", features = ["full"] }
|
tokio = { version = "1.6.0", features = ["full"] }
|
||||||
bencher = "0.1"
|
|
||||||
|
|
||||||
[[bench]]
|
|
||||||
name = "op_baseline"
|
|
||||||
harness = false
|
|
||||||
|
|
|
@ -1,88 +0,0 @@
|
||||||
use bencher::{benchmark_group, benchmark_main, Bencher};
|
|
||||||
|
|
||||||
use deno_core::error::AnyError;
|
|
||||||
use deno_core::op_async;
|
|
||||||
use deno_core::op_sync;
|
|
||||||
use deno_core::serialize_op_result;
|
|
||||||
use deno_core::v8;
|
|
||||||
use deno_core::JsRuntime;
|
|
||||||
use deno_core::Op;
|
|
||||||
use deno_core::OpState;
|
|
||||||
|
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
fn create_js_runtime() -> JsRuntime {
|
|
||||||
let mut runtime = JsRuntime::new(Default::default());
|
|
||||||
runtime.register_op("pi_json", op_sync(|_, _: (), _: ()| Ok(314159)));
|
|
||||||
runtime.register_op("pi_async", op_async(op_pi_async));
|
|
||||||
runtime.register_op("nop", |state, _| {
|
|
||||||
Op::Sync(serialize_op_result(Ok(9), state))
|
|
||||||
});
|
|
||||||
runtime.sync_ops_cache();
|
|
||||||
|
|
||||||
runtime
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is a function since async closures aren't stable
|
|
||||||
async fn op_pi_async(
|
|
||||||
_: Rc<RefCell<OpState>>,
|
|
||||||
_: (),
|
|
||||||
_: (),
|
|
||||||
) -> Result<i64, AnyError> {
|
|
||||||
Ok(314159)
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn bench_runtime_js_async(b: &mut Bencher, src: &str) {
|
|
||||||
let mut runtime = create_js_runtime();
|
|
||||||
let tokio_runtime = tokio::runtime::Builder::new_current_thread()
|
|
||||||
.enable_all()
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
b.iter(|| {
|
|
||||||
runtime.execute("inner_loop", src).unwrap();
|
|
||||||
let future = runtime.run_event_loop();
|
|
||||||
tokio_runtime.block_on(future).unwrap();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bench_op_pi_json(b: &mut Bencher) {
|
|
||||||
bench_runtime_js(
|
|
||||||
b,
|
|
||||||
r#"for(let i=0; i < 1e3; i++) {
|
|
||||||
Deno.core.opSync("pi_json", null);
|
|
||||||
}"#,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bench_op_nop(b: &mut Bencher) {
|
|
||||||
bench_runtime_js(
|
|
||||||
b,
|
|
||||||
r#"for(let i=0; i < 1e3; i++) {
|
|
||||||
Deno.core.opSync("nop", null, null, null);
|
|
||||||
}"#,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bench_op_async(b: &mut Bencher) {
|
|
||||||
bench_runtime_js_async(
|
|
||||||
b,
|
|
||||||
r#"for(let i=0; i < 1e3; i++) {
|
|
||||||
Deno.core.opAsync("pi_async", null);
|
|
||||||
}"#,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
benchmark_group!(benches, bench_op_pi_json, bench_op_nop, bench_op_async);
|
|
||||||
benchmark_main!(benches);
|
|
|
@ -20,7 +20,7 @@ percent-encoding = "2.1.0"
|
||||||
serde = { version = "1.0.125", features = ["derive"] }
|
serde = { version = "1.0.125", features = ["derive"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bencher = "0.1"
|
deno_bench_util = { version = "0.1.0", path = "../../bench_util" }
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "url_ops"
|
name = "url_ops"
|
||||||
|
|
|
@ -1,35 +1,28 @@
|
||||||
use bencher::{benchmark_group, benchmark_main, Bencher};
|
use deno_bench_util::bench_js_sync;
|
||||||
|
use deno_bench_util::bench_or_profile;
|
||||||
|
use deno_bench_util::bencher::{benchmark_group, Bencher};
|
||||||
|
|
||||||
use deno_core::v8;
|
|
||||||
use deno_core::JsRuntime;
|
use deno_core::JsRuntime;
|
||||||
use deno_core::RuntimeOptions;
|
|
||||||
|
|
||||||
fn create_js_runtime() -> JsRuntime {
|
fn setup(runtime: &mut JsRuntime) {
|
||||||
let mut runtime = JsRuntime::new(RuntimeOptions {
|
// TODO(@AaronO): support caller provided extensions in deno_bench_util
|
||||||
extensions: vec![deno_url::init()],
|
let mut ext = deno_url::init();
|
||||||
..Default::default()
|
|
||||||
});
|
for (name, op_fn) in ext.init_ops().unwrap() {
|
||||||
|
runtime.register_op(name, op_fn);
|
||||||
|
}
|
||||||
|
for (filename, src) in ext.init_js() {
|
||||||
|
runtime.execute(filename, src).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
runtime
|
runtime
|
||||||
.execute("setup", "const { URL } = globalThis.__bootstrap.url;")
|
.execute("setup", "const { URL } = globalThis.__bootstrap.url;")
|
||||||
.unwrap();
|
.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) {
|
fn bench_url_parse(b: &mut Bencher) {
|
||||||
bench_runtime_js(b, r#"new URL(`http://www.google.com/`);"#);
|
bench_js_sync(b, r#"new URL(`http://www.google.com/`);"#, setup);
|
||||||
}
|
}
|
||||||
|
|
||||||
benchmark_group!(benches, bench_url_parse,);
|
benchmark_group!(benches, bench_url_parse,);
|
||||||
benchmark_main!(benches);
|
bench_or_profile!(benches);
|
||||||
|
|
Loading…
Reference in a new issue