summaryrefslogtreecommitdiff
path: root/bench_util
diff options
context:
space:
mode:
Diffstat (limited to 'bench_util')
-rw-r--r--bench_util/benches/op_baseline.rs20
-rw-r--r--bench_util/src/js_runtime.rs21
2 files changed, 21 insertions, 20 deletions
diff --git a/bench_util/benches/op_baseline.rs b/bench_util/benches/op_baseline.rs
index ecce90bec..0496a034b 100644
--- a/bench_util/benches/op_baseline.rs
+++ b/bench_util/benches/op_baseline.rs
@@ -6,20 +6,24 @@ 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::Extension;
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();
+fn setup() -> Vec<Extension> {
+ vec![Extension::builder()
+ .ops(vec![
+ ("pi_json", op_sync(|_, _: (), _: ()| Ok(314159))),
+ ("pi_async", op_async(op_pi_async)),
+ (
+ "nop",
+ Box::new(|state, _| Op::Sync(serialize_op_result(Ok(9), state))),
+ ),
+ ])
+ .build()]
}
// this is a function since async closures aren't stable
diff --git a/bench_util/src/js_runtime.rs b/bench_util/src/js_runtime.rs
index cc704ff97..f0280b072 100644
--- a/bench_util/src/js_runtime.rs
+++ b/bench_util/src/js_runtime.rs
@@ -1,20 +1,17 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use bencher::Bencher;
use deno_core::v8;
+use deno_core::Extension;
use deno_core::JsRuntime;
+use deno_core::RuntimeOptions;
use crate::profiling::is_profiling;
-pub fn create_js_runtime(setup: impl FnOnce(&mut JsRuntime)) -> JsRuntime {
- let mut rt = JsRuntime::new(Default::default());
-
- // Caller provided setup
- setup(&mut rt);
-
- // Init ops
- rt.sync_ops_cache();
-
- rt
+pub fn create_js_runtime(setup: impl FnOnce() -> Vec<Extension>) -> JsRuntime {
+ JsRuntime::new(RuntimeOptions {
+ extensions: setup(),
+ ..Default::default()
+ })
}
fn loop_code(iters: u64, src: &str) -> String {
@@ -24,7 +21,7 @@ fn loop_code(iters: u64, src: &str) -> String {
pub fn bench_js_sync(
b: &mut Bencher,
src: &str,
- setup: impl FnOnce(&mut JsRuntime),
+ setup: impl FnOnce() -> Vec<Extension>,
) {
let mut runtime = create_js_runtime(setup);
let scope = &mut runtime.handle_scope();
@@ -50,7 +47,7 @@ pub fn bench_js_sync(
pub fn bench_js_async(
b: &mut Bencher,
src: &str,
- setup: impl FnOnce(&mut JsRuntime),
+ setup: impl FnOnce() -> Vec<Extension>,
) {
let mut runtime = create_js_runtime(setup);
let tokio_runtime = tokio::runtime::Builder::new_current_thread()