0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/querystring/querystring-stringify.js
Rich Trott 3c31bfff65 benchmark,lib,test,tools: use consistent quotes
In preparation for a linting rule, use consistent quotation for
properties in objects.

PR-URL: https://github.com/nodejs/node/pull/19156
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Roman Reiss <me@silverwind.io>
2018-03-07 19:06:44 -08:00

40 lines
900 B
JavaScript

'use strict';
const common = require('../common.js');
const querystring = require('querystring');
const bench = common.createBenchmark(main, {
type: ['noencode', 'encodemany', 'encodelast'],
n: [1e7],
});
function main({ type, n }) {
const inputs = {
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'
}
};
const input = inputs[type];
// Force-optimize querystring.stringify() so that the benchmark doesn't get
// disrupted by the optimizer kicking in halfway through.
for (const name in inputs)
querystring.stringify(inputs[name]);
bench.start();
for (var i = 0; i < n; i += 1)
querystring.stringify(input);
bench.end(n);
}