deno/bench_util
Matt Mastracci e55b448730
feat(core) deno_core::extension! macro to simplify extension registration (#18210)
This implements two macros to simplify extension registration and centralize a lot of the boilerplate as a base for future improvements:

* `deno_core::ops!` registers a block of `#[op]`s, optionally with type
parameters, useful for places where we share lists of ops
* `deno_core::extension!` is used to register an extension, and creates
two methods that can be used at runtime/snapshot generation time:
`init_ops` and `init_ops_and_esm`.

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-03-17 18:22:15 +00:00
..
benches feat(core) deno_core::extension! macro to simplify extension registration (#18210) 2023-03-17 18:22:15 +00:00
Cargo.toml chore: forward v1.31.3 release commit to main (#18222) 2023-03-16 17:09:26 +09:00
js_runtime.rs refactor(core): remove RuntimeOptions::extensions_with_js (#18099) 2023-03-09 19:22:27 -05:00
lib.rs chore: update copyright year to 2023 (#17247) 2023-01-02 21:00:42 +00:00
profiling.rs chore: use rustfmt imports_granularity option (#17421) 2023-01-14 23:18:58 -05:00
README.md perf(ops): Monomorphic sync op calls (#15337) 2022-08-11 15:56:56 +02:00

Benching utility for deno_core op system

Example:

use deno_bench_util::bench_or_profile;
use deno_bench_util::bencher::{benchmark_group, Bencher};
use deno_bench_util::bench_js_sync};

use deno_core::op_sync;
use deno_core::serialize_op_result;
use deno_core::Extension;
use deno_core::JsRuntime;
use deno_core::Op;
use deno_core::OpState;

fn setup() -> Vec<Extension> {
  let custom_ext = Extension::builder()
    .ops(vec![
      ("op_nop", |state, _| {
        Op::Sync(serialize_op_result(Ok(9), state))
      }),
    ])
    .build();
  
  vec![
    // deno_{ext}::init(...),
    custom_ext,
  ]
}

fn bench_op_nop(b: &mut Bencher) {
  bench_js_sync(b, r#"Deno.core.ops.op_nop();"#, setup);
}

benchmark_group!(benches, bench_op_nop);
bench_or_profile!(benches);