Skip to content

Commit abd9d6b

Browse files
committed
benchmarks: add simple parse and test benchmarks for URLPattern
1 parent 2bd5694 commit abd9d6b

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

benchmark/url/urlpattern-parse.js

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

benchmark/url/urlpattern-test.js

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

0 commit comments

Comments
 (0)