-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ext/webidl): Add dictionary converter microbenchmark (#17435)
This commits add a `webidl.createDictionaryConverter` converter microbenchmark. There are 2 PRs currently open that need a microbenchmark for webidl dictionary converter. See #16594 and #16407 Closes #17436
- Loading branch information
1 parent
1a06380
commit 7f65a5d
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |