forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
url: remove #context from URLSearchParams
PR-URL: nodejs#51520 Fixes: nodejs#51518 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
- Loading branch information
1 parent
c71a6a0
commit 874ca58
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