-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
url: don't update URL immediately on update to URLSearchParams
PR-URL: #51520 Fixes: #51518 Backport-PR-URL: #51559 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
Showing
5 changed files
with
176 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(url.searchParams); | ||
|
||
const method = getMethod(url, property); | ||
|
||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
method(i); | ||
} | ||
bench.end(n); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters