benchmark: add simple parse and test benchmarks for URLPattern
Some checks are pending
Coverage Linux (without intl) / coverage-linux-without-intl (push) Waiting to run
Coverage Linux / coverage-linux (push) Waiting to run
Coverage Windows / coverage-windows (push) Waiting to run
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
James M Snell 2025-02-04 09:57:45 -08:00 committed by GitHub
parent 316ac8c250
commit 3207fda22c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,28 @@
'use strict';
const common = require('../common.js');
const { URLPattern } = require('url');
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);
}

View File

@ -0,0 +1,30 @@
'use strict';
const common = require('../common.js');
const { URLPattern } = require('url');
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.
}