Skip to content

Commit cd5ab79

Browse files
feat(bench): add URLPattern benchmark script and finalize wiring
1 parent 98cf7e7 commit cd5ab79

4 files changed

Lines changed: 23 additions & 0 deletions

File tree

bench/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ and `/tmp/deno/bin/deno`, and LLRT at `~/.llrt/bin/llrt`, `~/.local/bin/llrt`, o
4343
| **sha256** | 20 000 × SHA-256 of a 4 KiB buffer via `crypto.subtle.digest` — crypto backend + per-call async overhead. |
4444
| **crypto** | 2 000 × (HMAC-SHA-256 sign + AES-256-GCM encrypt/decrypt of 1 KiB, fresh IV) — the key-based `subtle` surface + `getRandomValues`. |
4545
| **url** | 100 000 × `new URL(...)` + component reads — for esrun one JS↔Rust op per parse; the others parse natively. |
46+
| **urlpattern** | 50 000 × `new URLPattern(...)` + `.test()` matches — polyfilled inside V8 vs native. |
4647
| **encoding** | 100 000 × `TextEncoder`/`TextDecoder` UTF-8 round trips — op crossings riding V8's native transcoding. |
4748
| **base64** | 10 000 × `btoa`/`atob` of a 1 KiB string — op-backed for esrun; native elsewhere. |
4849
| **structured** | 50 000 × `structuredClone` of a nested object — pure-JS recursive clone for esrun. |

bench/scripts/urlpattern.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// URLPattern benchmark: parsing and matching complex routes.
2+
(async () => {
3+
const N = 50_000;
4+
const run = (n) => {
5+
let acc = 0;
6+
for (let i = 0; i < n; i++) {
7+
const p = new URLPattern('/api/v1/users/:id/posts/:postId', 'https://api.example.com');
8+
if (p.test('https://api.example.com/api/v1/users/' + i + '/posts/' + (i + 1))) {
9+
acc++;
10+
}
11+
}
12+
return acc;
13+
};
14+
run(N / 10); // untimed JIT warmup
15+
const t0 = performance.now();
16+
const acc = run(N);
17+
const t1 = performance.now();
18+
if (acc === -1) console.log(acc); // defeat dead-code elimination
19+
console.log("RESULT_MS=" + (t1 - t0).toFixed(2));
20+
})();

crates/runtime/src/prelude.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub(crate) fn source() -> String {
2020
include_str!("prelude/base64.js"),
2121
include_str!("prelude/structured-clone.js"),
2222
include_str!("prelude/url.js"),
23+
include_str!("prelude/urlpattern.js"),
2324
// events before abort: AbortSignal extends EventTarget.
2425
include_str!("prelude/events.js"),
2526
include_str!("prelude/abort.js"),

site/app/docs/globals/page.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const groups = [
2828
items: [
2929
{ n: "URL", s: "yes" },
3030
{ n: "URLSearchParams", s: "yes" },
31+
{ n: "URLPattern", s: "yes" },
3132
],
3233
},
3334
{

0 commit comments

Comments
 (0)