1'use strict'; 2const common = require('../common.js'); 3const querystring = require('querystring'); 4 5const bench = common.createBenchmark(main, { 6 type: ['noencode', 'encodemany', 'encodelast', 'array', 'multiprimitives'], 7 n: [1e6], 8}); 9 10function main({ type, n }) { 11 const inputs = { 12 noencode: { 13 foo: 'bar', 14 baz: 'quux', 15 xyzzy: 'thud', 16 }, 17 encodemany: { 18 '\u0080\u0083\u0089': 'bar', 19 '\u008C\u008E\u0099': 'quux', 20 'xyzzy': '\u00A5q\u00A3r', 21 }, 22 encodelast: { 23 foo: 'bar', 24 baz: 'quux', 25 xyzzy: 'thu\u00AC', 26 }, 27 array: { 28 foo: [], 29 baz: ['bar'], 30 xyzzy: ['bar', 'quux', 'thud'], 31 }, 32 multiprimitives: { 33 foo: false, 34 bar: -13.37, 35 baz: '', 36 }, 37 }; 38 const input = inputs[type]; 39 40 // Force-optimize querystring.stringify() so that the benchmark doesn't get 41 // disrupted by the optimizer kicking in halfway through. 42 for (const name in inputs) 43 querystring.stringify(inputs[name]); 44 45 bench.start(); 46 for (let i = 0; i < n; i += 1) 47 querystring.stringify(input); 48 bench.end(n); 49} 50