11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common.js'); 31cb0ef41Sopenharmony_ciconst querystring = require('querystring'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 61cb0ef41Sopenharmony_ci type: ['noencode', 'encodemany', 'encodelast', 'array', 'multiprimitives'], 71cb0ef41Sopenharmony_ci n: [1e6], 81cb0ef41Sopenharmony_ci}); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cifunction main({ type, n }) { 111cb0ef41Sopenharmony_ci const inputs = { 121cb0ef41Sopenharmony_ci noencode: { 131cb0ef41Sopenharmony_ci foo: 'bar', 141cb0ef41Sopenharmony_ci baz: 'quux', 151cb0ef41Sopenharmony_ci xyzzy: 'thud', 161cb0ef41Sopenharmony_ci }, 171cb0ef41Sopenharmony_ci encodemany: { 181cb0ef41Sopenharmony_ci '\u0080\u0083\u0089': 'bar', 191cb0ef41Sopenharmony_ci '\u008C\u008E\u0099': 'quux', 201cb0ef41Sopenharmony_ci 'xyzzy': '\u00A5q\u00A3r', 211cb0ef41Sopenharmony_ci }, 221cb0ef41Sopenharmony_ci encodelast: { 231cb0ef41Sopenharmony_ci foo: 'bar', 241cb0ef41Sopenharmony_ci baz: 'quux', 251cb0ef41Sopenharmony_ci xyzzy: 'thu\u00AC', 261cb0ef41Sopenharmony_ci }, 271cb0ef41Sopenharmony_ci array: { 281cb0ef41Sopenharmony_ci foo: [], 291cb0ef41Sopenharmony_ci baz: ['bar'], 301cb0ef41Sopenharmony_ci xyzzy: ['bar', 'quux', 'thud'], 311cb0ef41Sopenharmony_ci }, 321cb0ef41Sopenharmony_ci multiprimitives: { 331cb0ef41Sopenharmony_ci foo: false, 341cb0ef41Sopenharmony_ci bar: -13.37, 351cb0ef41Sopenharmony_ci baz: '', 361cb0ef41Sopenharmony_ci }, 371cb0ef41Sopenharmony_ci }; 381cb0ef41Sopenharmony_ci const input = inputs[type]; 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci // Force-optimize querystring.stringify() so that the benchmark doesn't get 411cb0ef41Sopenharmony_ci // disrupted by the optimizer kicking in halfway through. 421cb0ef41Sopenharmony_ci for (const name in inputs) 431cb0ef41Sopenharmony_ci querystring.stringify(inputs[name]); 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci bench.start(); 461cb0ef41Sopenharmony_ci for (let i = 0; i < n; i += 1) 471cb0ef41Sopenharmony_ci querystring.stringify(input); 481cb0ef41Sopenharmony_ci bench.end(n); 491cb0ef41Sopenharmony_ci} 50