Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmarks: add simple parse and test benchmarks for URLPattern #56882

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions benchmark/url/urlpattern-parse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';
const common = require('../common.js');
const { URLPattern } = require('url');
jasnell marked this conversation as resolved.
Show resolved Hide resolved
const { ok } = require('assert');

const tests = [
'https://(sub.)?example(.com/)foo',
{ 'hostname': 'xn--caf-dma.com' },
{ 'pathname': '/foo', 'search': 'bar', 'hash': 'baz',
'baseURL': 'https://example.com:8080' },
{ 'pathname': '/([[a-z]--a])' },
];

const bench = common.createBenchmark(main, {
pattern: tests.map(JSON.stringify),
n: [1e5],
});

function main({ pattern, n }) {
const inputPattern = JSON.parse(pattern);
let deadcode;
bench.start();
for (let i = 0; i < n; i += 1) {
deadcode = new URLPattern(inputPattern);
}
bench.end(n);
ok(deadcode);
}
30 changes: 30 additions & 0 deletions benchmark/url/urlpattern-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';
const common = require('../common.js');
const { URLPattern } = require('url');
jasnell marked this conversation as resolved.
Show resolved Hide resolved
const { notStrictEqual } = require('assert');

const tests = [
'https://(sub.)?example(.com/)foo',
{ 'hostname': 'xn--caf-dma.com' },
{ 'pathname': '/foo', 'search': 'bar', 'hash': 'baz',
'baseURL': 'https://example.com:8080' },
{ 'pathname': '/([[a-z]--a])' },
];

const bench = common.createBenchmark(main, {
pattern: tests.map(JSON.stringify),
n: [1e5],
});

function main({ pattern, n }) {
const inputPattern = JSON.parse(pattern);
const urlpattern = new URLPattern(inputPattern);

let deadcode;
bench.start();
for (let i = 0; i < n; i += 1) {
deadcode = urlpattern.test('https://sub.example.com/foo');
}
bench.end(n);
notStrictEqual(deadcode, undefined); // We don't care if it is true or false.
}
Loading