Skip to content

Commit

Permalink
url: add benchmark to check impact of searchParams checking
Browse files Browse the repository at this point in the history
  • Loading branch information
MattIPv4 committed Jan 19, 2024
1 parent 5d9bd42 commit c69208c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions benchmark/url/url-searchparams-update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
const common = require('../common.js');

const bench = common.createBenchmark(main, {
searchParams: ['true', 'false'],
property: ['pathname', 'search'],
n: [1e6],
});

function main({ searchParams, property, n }) {
const url = new URL('https://nodejs.org');
if (searchParams === 'true') url.searchParams;

const method = property === 'pathname' ?
(n => url.pathname = `/${n}`) :
(n => url.search = `?${n}`);

bench.start();
for (let i = 0; i < n; i++) {
method(n);
}
bench.end(n);
}

0 comments on commit c69208c

Please sign in to comment.