Skip to content

Commit

Permalink
benchmark: add a benchmark for URLSearchParams.toString()
Browse files Browse the repository at this point in the history
  • Loading branch information
debadree25 committed Feb 24, 2023
1 parent 42be7f6 commit e717c91
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions benchmark/url/url-searchparams-toString.js
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);
}

0 comments on commit e717c91

Please sign in to comment.