diff options
author | randomicon00 <20146907+randomicon00@users.noreply.github.com> | 2022-05-17 14:52:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-17 19:22:48 +0530 |
commit | e58f77e431c7f9404bd76f6b7cf5b6d7841c0b0f (patch) | |
tree | ba49dbb466b24c7816ba1424ad11d7292d9340ef /ext/web/benches/encoding.rs | |
parent | 8879244f72aebd2fd4d3ae34a064ff04069a6b58 (diff) |
perf(ext/web): Add fast path for non-streaming TextDecoder (#14217)
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
Diffstat (limited to 'ext/web/benches/encoding.rs')
-rw-r--r-- | ext/web/benches/encoding.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/ext/web/benches/encoding.rs b/ext/web/benches/encoding.rs new file mode 100644 index 000000000..5b8b2a988 --- /dev/null +++ b/ext/web/benches/encoding.rs @@ -0,0 +1,54 @@ +use deno_core::Extension; + +use deno_bench_util::bench_js_sync; +use deno_bench_util::bench_or_profile; +use deno_bench_util::bencher::{benchmark_group, Bencher}; +use deno_web::BlobStore; + +struct Permissions; + +impl deno_web::TimersPermission for Permissions { + fn allow_hrtime(&mut self) -> bool { + false + } + fn check_unstable( + &self, + _state: &deno_core::OpState, + _api_name: &'static str, + ) { + unreachable!() + } +} + +fn setup() -> Vec<Extension> { + vec![ + deno_webidl::init(), + deno_url::init(), + deno_web::init::<Permissions>(BlobStore::default(), None), + Extension::builder() + .js(vec![( + "setup", + Box::new(|| { + Ok( + r#" + const { TextDecoder } = globalThis.__bootstrap.encoding; + const hello12k = Deno.core.encode("hello world\n".repeat(1e3)); + "# + .to_owned(), + ) + }), + )]) + .state(|state| { + state.put(Permissions {}); + Ok(()) + }) + .build(), + ] +} + +fn bench_encode_12kb(b: &mut Bencher) { + bench_js_sync(b, r#"new TextDecoder().decode(hello12k);"#, setup); +} + +benchmark_group!(benches, bench_encode_12kb); +bench_or_profile!(benches); |