forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: add a benchmark for URLSearchParams.toString()
Refs: nodejs/performance#56
- Loading branch information
1 parent
42be7f6
commit e717c91
Showing
1 changed file
with
48 additions
and
0 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,48 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
|
||
const values = { | ||
noencode: { | ||
foo: 'bar', | ||
baz: 'quux', | ||
xyzzy: 'thud', | ||
}, | ||
encodemany: { | ||
'\u0080\u0083\u0089': 'bar', | ||
'\u008C\u008E\u0099': 'quux', | ||
'xyzzy': '\u00A5q\u00A3r', | ||
}, | ||
encodelast: { | ||
foo: 'bar', | ||
baz: 'quux', | ||
xyzzy: 'thu\u00AC', | ||
}, | ||
array: { | ||
foo: [], | ||
baz: ['bar'], | ||
xyzzy: ['bar', 'quux', 'thud'], | ||
}, | ||
multiprimitives: { | ||
foo: false, | ||
bar: -13.37, | ||
baz: 'baz', | ||
}, | ||
}; | ||
|
||
const bench = common.createBenchmark(main, { | ||
type: ['noencode', 'encodemany', 'encodelast', 'array', 'multiprimitives'], | ||
n: [1e6], | ||
}); | ||
|
||
function main({ n, type }) { | ||
const input = values[type]; | ||
|
||
// force optimisation | ||
for (const name in values) | ||
new URLSearchParams(values[name]).toString(); | ||
|
||
bench.start(); | ||
for (let i = 0; i < n; i++) | ||
new URLSearchParams(input).toString(); | ||
bench.end(n); | ||
} |