Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ext/webidl): Add dictionary converter microbenchmark #17435

Merged
merged 5 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions ext/webidl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ path = "lib.rs"

[dependencies]
deno_core.workspace = true

[dev-dependencies]
deno_bench_util.workspace = true

[[bench]]
name = "dict"
harness = false
35 changes: 35 additions & 0 deletions ext/webidl/benches/dict.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.

// deno-lint-ignore-file

const { createDictionaryConverter, converters } = globalThis.__bootstrap.webidl;

const TextDecodeOptions = createDictionaryConverter(
"TextDecodeOptions",
[
{
key: "stream",
converter: converters.boolean,
defaultValue: false,
},
],
);

// Sanity check
{
const o = TextDecodeOptions(undefined);
if (o.stream !== false) {
throw new Error("Unexpected stream value");
}
}

function handwrittenConverter(V) {
const defaultValue = { stream: false };
if (V === undefined || V === null) {
return defaultValue;
}
if (V.stream !== undefined) {
defaultValue.stream = !!V.stream;
}
return defaultValue;
}
42 changes: 42 additions & 0 deletions ext/webidl/benches/dict.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.

use deno_bench_util::bench_js_sync;
use deno_bench_util::bench_or_profile;
use deno_bench_util::bencher::benchmark_group;
use deno_bench_util::bencher::Bencher;

use deno_core::Extension;

fn setup() -> Vec<Extension> {
vec![
deno_webidl::init(),
Extension::builder("deno_webidl_bench")
.js(vec![("setup", include_str!("dict.js"))])
.build(),
]
}

fn converter_undefined(b: &mut Bencher) {
bench_js_sync(b, r#"TextDecodeOptions(undefined);"#, setup);
}

fn handwritten_baseline_undefined(b: &mut Bencher) {
bench_js_sync(b, r#"handwrittenConverter(undefined)"#, setup);
}

fn converter_object(b: &mut Bencher) {
bench_js_sync(b, r#"TextDecodeOptions({});"#, setup);
}

fn handwritten_baseline_object(b: &mut Bencher) {
bench_js_sync(b, r#"handwrittenConverter({})"#, setup);
}

benchmark_group!(
benches,
converter_undefined,
handwritten_baseline_undefined,
converter_object,
handwritten_baseline_object,
);
bench_or_profile!(benches);