Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,41 @@
'use strict';
const common = require('../common.js');
const url = require('url');
const assert = require('assert');
const bench = common.createBenchmark(main, {
type: common.urlDataTypes,
e: [1],
});
function main({ type, e }) {
const data = common.bakeUrlData(type, e, false, false).map((i) => url.parse(i));
const obj = url.parse(data[0]);
const noDead = {
protocol: obj.protocol,
auth: obj.auth,
host: obj.host,
hostname: obj.hostname,
port: obj.port,
pathname: obj.pathname,
search: obj.search,
hash: obj.hash,
};
const len = data.length;
// It's necessary to assign the values to an object
// to avoid loop invariant code motion.
bench.start();
for (let i = 0; i < len; i++) {
const obj = data[i];
noDead.protocol = obj.protocol;
noDead.auth = obj.auth;
noDead.host = obj.host;
noDead.hostname = obj.hostname;
noDead.port = obj.port;
noDead.pathname = obj.pathname;
noDead.search = obj.search;
noDead.hash = obj.hash;
}
bench.end(len);
assert.ok(noDead);
}

View File

@ -0,0 +1,22 @@
'use strict';
const common = require('../common.js');
const url = require('url');
const assert = require('assert');
const bench = common.createBenchmark(main, {
type: common.urlDataTypes,
e: [1],
});
function main({ e, type }) {
const data = common.bakeUrlData(type, e, false, false);
let result = url.parse(data[0]); // Avoid dead code elimination
bench.start();
for (let i = 0; i < data.length; ++i) {
result = url.parse(data[i]);
}
bench.end(data.length);
assert.ok(result);
}

View File

@ -0,0 +1,46 @@
'use strict';
const common = require('../common.js');
const querystring = require('querystring');
const searchParams = common.searchParams;
const bench = common.createBenchmark(main, {
searchParam: Object.keys(searchParams),
method: ['legacy', 'whatwg'],
n: [1e6],
});
function useLegacy(n, input) {
querystring.parse(input);
bench.start();
for (let i = 0; i < n; i += 1) {
querystring.parse(input);
}
bench.end(n);
}
function useWHATWG(n, param) {
new URLSearchParams(param);
bench.start();
for (let i = 0; i < n; i += 1) {
new URLSearchParams(param);
}
bench.end(n);
}
function main({ searchParam, n, method }) {
const param = searchParams[searchParam];
if (!param) {
throw new Error(`Unknown search parameter type "${searchParam}"`);
}
switch (method) {
case 'legacy':
useLegacy(n, param);
break;
case 'whatwg':
useWHATWG(n, param);
break;
default:
throw new Error(`Unknown method ${method}`);
}
}

View File

@ -0,0 +1,48 @@
'use strict';
const common = require('../common.js');
const querystring = require('querystring');
const searchParams = common.searchParams;
const bench = common.createBenchmark(main, {
searchParam: Object.keys(searchParams),
method: ['legacy', 'whatwg'],
n: [1e6],
});
function useLegacy(n, input, prop) {
const obj = querystring.parse(input);
querystring.stringify(obj);
bench.start();
for (let i = 0; i < n; i += 1) {
querystring.stringify(obj);
}
bench.end(n);
}
function useWHATWG(n, param, prop) {
const obj = new URLSearchParams(param);
obj.toString();
bench.start();
for (let i = 0; i < n; i += 1) {
obj.toString();
}
bench.end(n);
}
function main({ searchParam, n, method }) {
const param = searchParams[searchParam];
if (!param) {
throw new Error(`Unknown search parameter type "${searchParam}"`);
}
switch (method) {
case 'legacy':
useLegacy(n, param);
break;
case 'whatwg':
useWHATWG(n, param);
break;
default:
throw new Error(`Unknown method ${method}`);
}
}

View File

@ -0,0 +1,53 @@
'use strict';
const common = require('../common.js');
const url = require('url');
const URL = url.URL;
const assert = require('assert');
const bench = common.createBenchmark(main, {
type: common.urlDataTypes,
method: ['legacy', 'whatwg'],
e: [1],
});
function useLegacy(data) {
const obj = url.parse(data[0]);
const len = data.length;
let noDead = url.format(obj);
bench.start();
for (let i = 0; i < len; i++) {
noDead = data[i].toString();
}
bench.end(len);
return noDead;
}
function useWHATWG(data) {
const obj = new URL(data[0]);
const len = data.length;
let noDead = obj.toString();
bench.start();
for (let i = 0; i < len; i++) {
noDead = data[i].toString();
}
bench.end(len);
return noDead;
}
function main({ type, e, method }) {
const data = common.bakeUrlData(type, e, false, false);
let noDead; // Avoid dead code elimination.
switch (method) {
case 'legacy':
noDead = useLegacy(data);
break;
case 'whatwg':
noDead = useWHATWG(data);
break;
default:
throw new Error(`Unknown method ${method}`);
}
assert.ok(noDead);
}

View File

@ -0,0 +1,27 @@
'use strict';
const common = require('../common.js');
const url = require('url');
const inputs = {
slashes: { slashes: true, host: 'localhost' },
file: { protocol: 'file:', pathname: '/foo' },
};
const bench = common.createBenchmark(main, {
type: Object.keys(inputs),
n: [25e6],
});
function main({ type, n }) {
const input = inputs[type];
// Force-optimize url.format() so that the benchmark doesn't get
// disrupted by the optimizer kicking in halfway through.
for (const name in inputs)
url.format(inputs[name]);
bench.start();
for (let i = 0; i < n; i += 1)
url.format(input);
bench.end(n);
}

View File

@ -0,0 +1,22 @@
'use strict';
const common = require('../common.js');
const url = require('url');
const inputs = {
normal: 'http://foo.com/bar',
escaped: 'https://foo.bar/{}^`/abcd',
};
const bench = common.createBenchmark(main, {
type: Object.keys(inputs),
n: [1e7],
});
function main({ type, n }) {
const input = inputs[type];
bench.start();
for (let i = 0; i < n; i += 1)
url.parse(input);
bench.end(n);
}

View File

@ -0,0 +1,29 @@
'use strict';
const common = require('../common.js');
const url = require('url');
const hrefs = common.urls;
hrefs.noscheme = 'some.ran/dom/url.thing?oh=yes#whoo';
const paths = {
'up': '../../../../../etc/passwd',
'sibling': '../foo/bar?baz=boom',
'foo/bar': 'foo/bar',
'withscheme': 'http://nodejs.org',
'down': './foo/bar?baz',
};
const bench = common.createBenchmark(main, {
href: Object.keys(hrefs),
path: Object.keys(paths),
n: [1e5],
});
function main({ n, href, path }) {
const h = hrefs[href];
const p = paths[path];
bench.start();
for (let i = 0; i < n; i += 1)
url.resolve(h, p);
bench.end(n);
}

View File

@ -0,0 +1,19 @@
'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
type: ['URL', 'URLSearchParams'],
n: [1e3, 1e6],
});
function main({ type, n }) {
const params = type === 'URL' ?
new URL('https://nodejs.org').searchParams :
new URLSearchParams();
bench.start();
for (let i = 0; i < n; i++) {
params.append('test', i);
}
bench.end(n);
}

View File

@ -0,0 +1,79 @@
'use strict';
const common = require('../common.js');
const values = {
noencode: {
foo: 'bar',
baz: 'quux',
xyzzy: 'thud',
},
encodemany: {
'\u0080\u0083\u0089': 'bar',
'\u008C\u008E\u0099': 'quux',
'xyzzy': '\u00A5q\u00A3r',
},
encodelast: {
foo: 'bar',
baz: 'quux',
xyzzy: 'thu\u00AC',
},
array: {
foo: [],
baz: ['bar'],
xyzzy: ['bar', 'quux', 'thud'],
},
multiprimitives: {
foo: false,
bar: -13.37,
baz: 'baz',
},
};
function paramGenerator(paramType) {
const valueKeys = Object.keys(values);
switch (paramType) {
case 'string':
// Return the values object with all values as strings
return valueKeys.reduce((acc, key) => {
acc[key] = Object.keys(values[key]).reduce((acc, k, i) => {
acc += `${k}=${values[key][k]}${i < valueKeys.length - 1 ? '&' : ''}`;
return acc;
}, '');
return acc;
}, {});
case 'iterable':
// Return the values object with all values as iterable
return valueKeys.reduce((acc, key) => {
acc[key] = Object.keys(values[key]).reduce((acc, k) => {
acc.push([k, values[key][k]]);
return acc;
}, []);
return acc;
}, {});
case 'object':
// Return the values object with all values as objects
return values;
default:
}
}
const bench = common.createBenchmark(main, {
type: ['noencode', 'encodemany', 'encodelast', 'array', 'multiprimitives'],
inputType: ['string', 'iterable', 'object'],
n: [1e6],
});
function main({ n, type, inputType }) {
const inputs = paramGenerator(inputType);
const input = inputs[type];
// Force optimization before starting the benchmark
for (const name in inputs) {
new URLSearchParams(inputs[name]);
}
bench.start();
for (let i = 0; i < n; i += 1)
new URLSearchParams(input);
bench.end(n);
}

View File

@ -0,0 +1,57 @@
'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
loopMethod: ['forEach', 'iterator'],
n: [1e6],
});
const str = 'one=single&two=first&three=first&two=2nd&three=2nd&three=3rd';
function forEach(n) {
const params = new URLSearchParams(str);
const noDead = [];
const cb = (val, key) => {
noDead[0] = key;
noDead[1] = val;
};
bench.start();
for (let i = 0; i < n; i += 1)
params.forEach(cb);
bench.end(n);
assert.strictEqual(noDead[0], 'three');
assert.strictEqual(noDead[1], '3rd');
}
function iterator(n) {
const params = new URLSearchParams(str);
const noDead = [];
bench.start();
for (let i = 0; i < n; i += 1) {
for (const pair of params) {
noDead[0] = pair[0];
noDead[1] = pair[1];
}
}
bench.end(n);
assert.strictEqual(noDead[0], 'three');
assert.strictEqual(noDead[1], '3rd');
}
function main({ loopMethod, n }) {
switch (loopMethod) {
case 'forEach':
forEach(n);
break;
case 'iterator':
iterator(n);
break;
default:
throw new Error(`Unknown method ${loopMethod}`);
}
}

View File

@ -0,0 +1,21 @@
'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
accessMethod: ['get', 'getAll', 'has'],
param: ['one', 'two', 'three', 'nonexistent'],
n: [2e7],
});
const str = 'one=single&two=first&three=first&two=2nd&three=2nd&three=3rd';
function main({ accessMethod, param, n }) {
const params = new URLSearchParams(str);
if (!params[accessMethod])
throw new Error(`Unknown method ${accessMethod}`);
bench.start();
for (let i = 0; i < n; i += 1)
params[accessMethod](param);
bench.end(n);
}

View File

@ -0,0 +1,46 @@
'use strict';
const common = require('../common.js');
const inputs = {
wpt: 'wpt', // To work around tests
empty: '',
sorted: 'a&b&c&d&e&f&g&h&i&j&k&l&m&n&o&p&q&r&s&t&u&v&w&x&y&z',
almostsorted: 'a&b&c&d&e&f&g&i&h&j&k&l&m&n&o&p&q&r&s&t&u&w&v&x&y&z',
reversed: 'z&y&x&w&v&u&t&s&r&q&p&o&n&m&l&k&j&i&h&g&f&e&d&c&b&a',
random: 'm&t&d&c&z&v&a&n&p&y&u&o&h&l&f&j&e&q&b&i&s&x&k&w&r&g',
// 8 parameters
short: 'm&t&d&c&z&v&a&n',
// 88 parameters
long: 'g&r&t&h&s&r&d&w&b&n&h&k&x&m&k&h&o&e&x&c&c&g&e&b&p&p&s&n&j&b&y&z&' +
'u&l&o&r&w&a&u&l&m&f&j&q&p&f&e&y&e&n&e&l&m&w&u&w&t&n&t&q&v&y&c&o&' +
'k&f&j&i&l&m&g&j&d&i&z&q&p&x&q&q&d&n&y&w&g&i&v&r',
};
function getParams(str) {
const out = [];
for (const key of str.split('&')) {
out.push(key, '');
}
return out;
}
const bench = common.createBenchmark(main, {
type: Object.keys(inputs),
n: [1e6],
}, {
flags: ['--expose-internals'],
});
function main({ type, n }) {
const searchParams = require('internal/url').searchParamsSymbol;
const input = inputs[type];
const params = new URLSearchParams();
const array = getParams(input);
bench.start();
for (let i = 0; i < n; i++) {
params[searchParams] = array.slice();
params.sort();
}
bench.end(n);
}

View File

@ -0,0 +1,76 @@
'use strict';
const common = require('../common.js');
const values = {
noencode: {
foo: 'bar',
baz: 'quux',
xyzzy: 'thud',
},
encodemany: {
'\u0080\u0083\u0089': 'bar',
'\u008C\u008E\u0099': 'quux',
'xyzzy': '\u00A5q\u00A3r',
},
encodelast: {
foo: 'bar',
baz: 'quux',
xyzzy: 'thu\u00AC',
},
array: {
foo: [],
baz: ['bar'],
xyzzy: ['bar', 'quux', 'thud'],
},
multiprimitives: {
foo: false,
bar: -13.37,
baz: 'baz',
},
};
function paramGenerator(paramType) {
const valueKeys = Object.keys(values);
switch (paramType) {
case 'string':
// Return the values object with all values as strings
return valueKeys.reduce((acc, key) => {
const objectKeys = Object.keys(values[key]);
acc[key] = objectKeys.reduce((acc, k, i) => {
acc += `${k}=${values[key][k]}${i < objectKeys.length - 1 ? '&' : ''}`;
return acc;
}, '');
return acc;
}, {});
case 'iterable':
// Return the values object with all values as iterable
return valueKeys.reduce((acc, key) => {
acc[key] = Object.keys(values[key]).reduce((acc, k) => {
acc.push([k, values[key][k]]);
return acc;
}, []);
return acc;
}, {});
case 'object':
// Return the values object with all values as objects
return values;
default:
}
}
const bench = common.createBenchmark(main, {
type: ['noencode', 'encodemany', 'encodelast', 'array', 'multiprimitives'],
inputType: ['string', 'iterable', 'object'],
n: [1e6],
});
function main({ n, type, inputType }) {
const inputs = paramGenerator(inputType);
const input = inputs[type];
const u = new URLSearchParams(input);
bench.start();
for (let i = 0; i < n; i += 1)
u.toString();
bench.end(n);
}

View File

@ -0,0 +1,29 @@
'use strict';
const common = require('../common.js');
const assert = require('assert');
const bench = common.createBenchmark(main, {
searchParams: ['true', 'false'],
property: ['pathname', 'search', 'hash'],
n: [1e6],
});
function getMethod(url, property) {
if (property === 'pathname') return (x) => url.pathname = `/${x}`;
if (property === 'search') return (x) => url.search = `?${x}`;
if (property === 'hash') return (x) => url.hash = `#${x}`;
throw new Error(`Unsupported property "${property}"`);
}
function main({ searchParams, property, n }) {
const url = new URL('https://nodejs.org');
if (searchParams === 'true') assert.ok(url.searchParams);
const method = getMethod(url, property);
bench.start();
for (let i = 0; i < n; i++) {
method(i);
}
bench.end(n);
}

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.
}

View File

@ -0,0 +1,14 @@
'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
type: Object.keys(common.urls),
n: [1e6],
});
function main({ type, n }) {
bench.start();
for (let i = 0; i < n; i += 1)
URL.canParse(common.urls[type]);
bench.end(n);
}

View File

@ -0,0 +1,40 @@
'use strict';
const common = require('../common.js');
const url = require('url');
const URL = url.URL;
const assert = require('assert');
const bench = common.createBenchmark(main, {
type: common.urlDataTypes,
e: [1],
});
function main({ type, e }) {
const data = common.bakeUrlData(type, e, false, true);
const obj = new URL(data[0]);
const noDead = {
protocol: obj.protocol,
auth: `${obj.username}:${obj.password}`,
host: obj.host,
hostname: obj.hostname,
port: obj.port,
pathname: obj.pathname,
search: obj.search,
hash: obj.hash,
};
const len = data.length;
bench.start();
for (let i = 0; i < len; i++) {
const obj = data[i];
noDead.protocol = obj.protocol;
noDead.auth = `${obj.username}:${obj.password}`;
noDead.host = obj.host;
noDead.hostname = obj.hostname;
noDead.port = obj.port;
noDead.pathname = obj.pathname;
noDead.search = obj.search;
noDead.hash = obj.hash;
}
bench.end(len);
assert.ok(noDead);
}

View File

@ -0,0 +1,43 @@
'use strict';
const common = require('../common.js');
const { domainToASCII, domainToUnicode } = require('url');
const domains = {
empty: {
ascii: '',
unicode: '',
},
none: {
ascii: 'passports',
unicode: 'passports',
},
some: {
ascii: 'Paßstraße',
unicode: 'xn--Pastrae-1vae',
},
all: {
ascii: '他们不说中文',
unicode: 'xn--ihqwczyycu19kkg2c',
},
nonstring: {
ascii: { toString() { return ''; } },
unicode: { toString() { return ''; } },
},
};
const bench = common.createBenchmark(main, {
domain: Object.keys(domains),
to: ['ascii', 'unicode'],
n: [5e6],
});
function main({ n, to, domain }) {
const value = domains[domain][to];
const method = to === 'ascii' ? domainToASCII : domainToUnicode;
bench.start();
for (let i = 0; i < n; i++) {
method(value);
}
bench.end(n);
}

View File

@ -0,0 +1,42 @@
'use strict';
const common = require('../common.js');
const url = require('url');
const URL = url.URL;
const assert = require('assert');
const bench = common.createBenchmark(main, {
withBase: ['true', 'false'],
type: common.urlDataTypes,
e: [1],
});
function useWHATWGWithBase(data) {
const len = data.length;
let result = new URL(data[0][0], data[0][1]); // Avoid dead code elimination
bench.start();
for (let i = 0; i < len; ++i) {
const item = data[i];
result = new URL(item[0], item[1]);
}
bench.end(len);
return result;
}
function useWHATWGWithoutBase(data) {
const len = data.length;
let result = new URL(data[0]); // Avoid dead code elimination
bench.start();
for (let i = 0; i < len; ++i) {
result = new URL(data[i]);
}
bench.end(len);
return result;
}
function main({ e, type, withBase }) {
withBase = withBase === 'true';
const data = common.bakeUrlData(type, e, withBase, false);
const noDead = withBase ? useWHATWGWithBase(data) : useWHATWGWithoutBase(data);
assert.ok(noDead);
}

View File

@ -0,0 +1,59 @@
'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
withBase: ['true', 'false'],
type: ['wpt'], // Too many combinations - just use WPT by default
e: [1],
prop: ['href', 'origin', 'protocol',
'username', 'password', 'host', 'hostname', 'port',
'pathname', 'search', 'searchParams', 'hash'],
});
function setAndGet(data, prop) {
const len = data.length;
let result = data[0][prop];
bench.start();
for (let i = 0; i < len; ++i) {
result = data[i][prop];
data[i][prop] = result;
}
bench.end(len);
return result;
}
function get(data, prop) {
const len = data.length;
let result = data[0][prop];
bench.start();
for (let i = 0; i < len; ++i) {
result = data[i][prop]; // get
}
bench.end(len);
return result;
}
function main({ e, type, prop, withBase }) {
withBase = withBase === 'true';
const data = common.bakeUrlData(type, e, withBase, true);
switch (prop) {
case 'protocol':
case 'username':
case 'password':
case 'host':
case 'hostname':
case 'port':
case 'pathname':
case 'search':
case 'hash':
case 'href':
setAndGet(data, prop);
break;
case 'origin':
case 'searchParams':
get(data, prop);
break;
default:
throw new Error('Unknown prop');
}
}

View File

@ -0,0 +1,48 @@
'use strict';
const common = require('../common.js');
const { fileURLToPath, pathToFileURL } = require('node:url');
const isWindows = process.platform === 'win32';
const inputs = isWindows ? [
'C:\\foo',
'C:\\Program Files\\Music\\Web Sys\\main.html?REQUEST=RADIO',
'\\\\nas\\My Docs\\File.doc',
'\\\\?\\UNC\\server\\share\\folder\\file.txt',
'file:///C:/foo',
'file:///C:/dir/foo?query=1',
'file:///C:/dir/foo#fragment',
] : [
'/dev/null',
'/dev/null?key=param&bool',
'/dev/null?key=param&bool#hash',
'file:///dev/null',
'file:///dev/null?key=param&bool',
'file:///dev/null?key=param&bool#hash',
];
const bench = common.createBenchmark(
main,
{
method: ['pathToFileURL', 'fileURLToPath'],
input: Object.values(inputs),
n: [5e6],
},
{
combinationFilter: (p) => (
(isWindows ?
(!p.input.startsWith('file://') && p.method === 'pathToFileURL') :
p.method === 'pathToFileURL'
) ||
(p.input.startsWith('file://') && p.method === 'fileURLToPath')
),
},
);
function main({ method, input, n }) {
const methodFunc = method === 'fileURLToPath' ? fileURLToPath : pathToFileURL;
bench.start();
for (let i = 0; i < n; i++) {
methodFunc(input);
}
bench.end(n);
}

View File

@ -0,0 +1,23 @@
'use strict';
const common = require('../common.js');
const url = require('url');
const URL = url.URL;
const bench = common.createBenchmark(main, {
type: ['valid', 'invalid'],
e: [1e5],
});
// This benchmark is used to compare the `Invalid URL` path of the URL parser
function main({ type, e }) {
const url = type === 'valid' ? 'https://www.nodejs.org' : 'www.nodejs.org';
bench.start();
for (let i = 0; i < e; i++) {
try {
new URL(url);
} catch {
// do nothing
}
}
bench.end(e);
}