mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
4e6befd60e
PR-URL: https://github.com/nodejs/node/pull/54334 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
30 lines
804 B
JavaScript
30 lines
804 B
JavaScript
'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);
|
|
}
|