Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0ee9c34

Browse filesBrowse files
jasnelltargos
authored andcommitted
benchmark: add simple parse and test benchmarks for URLPattern
PR-URL: #56882 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
1 parent 5c82ef3 commit 0ee9c34
Copy full SHA for 0ee9c34

File tree

Expand file treeCollapse file tree

2 files changed

+58
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+58
-0
lines changed
Open diff view settings
Collapse file

‎benchmark/url/urlpattern-parse.js‎

Copy file name to clipboard
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const { URLPattern } = require('url');
4+
const { ok } = require('assert');
5+
6+
const tests = [
7+
'https://(sub.)?example(.com/)foo',
8+
{ 'hostname': 'xn--caf-dma.com' },
9+
{ 'pathname': '/foo', 'search': 'bar', 'hash': 'baz',
10+
'baseURL': 'https://example.com:8080' },
11+
{ 'pathname': '/([[a-z]--a])' },
12+
];
13+
14+
const bench = common.createBenchmark(main, {
15+
pattern: tests.map(JSON.stringify),
16+
n: [1e5],
17+
});
18+
19+
function main({ pattern, n }) {
20+
const inputPattern = JSON.parse(pattern);
21+
let deadcode;
22+
bench.start();
23+
for (let i = 0; i < n; i += 1) {
24+
deadcode = new URLPattern(inputPattern);
25+
}
26+
bench.end(n);
27+
ok(deadcode);
28+
}
Collapse file

‎benchmark/url/urlpattern-test.js‎

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const { URLPattern } = require('url');
4+
const { notStrictEqual } = require('assert');
5+
6+
const tests = [
7+
'https://(sub.)?example(.com/)foo',
8+
{ 'hostname': 'xn--caf-dma.com' },
9+
{ 'pathname': '/foo', 'search': 'bar', 'hash': 'baz',
10+
'baseURL': 'https://example.com:8080' },
11+
{ 'pathname': '/([[a-z]--a])' },
12+
];
13+
14+
const bench = common.createBenchmark(main, {
15+
pattern: tests.map(JSON.stringify),
16+
n: [1e5],
17+
});
18+
19+
function main({ pattern, n }) {
20+
const inputPattern = JSON.parse(pattern);
21+
const urlpattern = new URLPattern(inputPattern);
22+
23+
let deadcode;
24+
bench.start();
25+
for (let i = 0; i < n; i += 1) {
26+
deadcode = urlpattern.test('https://sub.example.com/foo');
27+
}
28+
bench.end(n);
29+
notStrictEqual(deadcode, undefined); // We don't care if it is true or false.
30+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.