summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--ext/webidl/Cargo.toml7
-rw-r--r--ext/webidl/benches/dict.js35
-rw-r--r--ext/webidl/benches/dict.rs42
4 files changed, 85 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ecb760ca7..13fcd9020 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1284,6 +1284,7 @@ dependencies = [
name = "deno_webidl"
version = "0.84.0"
dependencies = [
+ "deno_bench_util",
"deno_core",
]
diff --git a/ext/webidl/Cargo.toml b/ext/webidl/Cargo.toml
index 744115aec..e0a90ed4d 100644
--- a/ext/webidl/Cargo.toml
+++ b/ext/webidl/Cargo.toml
@@ -15,3 +15,10 @@ path = "lib.rs"
[dependencies]
deno_core.workspace = true
+
+[dev-dependencies]
+deno_bench_util.workspace = true
+
+[[bench]]
+name = "dict"
+harness = false
diff --git a/ext/webidl/benches/dict.js b/ext/webidl/benches/dict.js
new file mode 100644
index 000000000..353a630eb
--- /dev/null
+++ b/ext/webidl/benches/dict.js
@@ -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;
+}
diff --git a/ext/webidl/benches/dict.rs b/ext/webidl/benches/dict.rs
new file mode 100644
index 000000000..e7df8af62
--- /dev/null
+++ b/ext/webidl/benches/dict.rs
@@ -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);