From 6876ecc84f214561aa9c3c3dcc4c46cee3080b84 Mon Sep 17 00:00:00 2001 From: MattIPv4 Date: Fri, 19 Jan 2024 08:24:44 +0000 Subject: [PATCH] url: add benchmark to check impact of searchParams checking --- benchmark/url/url-searchparams-update.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 benchmark/url/url-searchparams-update.js diff --git a/benchmark/url/url-searchparams-update.js b/benchmark/url/url-searchparams-update.js new file mode 100644 index 00000000000000..483a55d331fdbb --- /dev/null +++ b/benchmark/url/url-searchparams-update.js @@ -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; // eslint-disable-line no-unused-expressions + + 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); +}