benchmark: reduce string concatenations
PR-URL: https://github.com/nodejs/node/pull/12455 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
bbbb1f6078
commit
22aa3d4899
@ -3,12 +3,13 @@
|
||||
const readline = require('readline');
|
||||
|
||||
function pad(input, minLength, fill) {
|
||||
var result = input + '';
|
||||
return fill.repeat(Math.max(0, minLength - result.length)) + result;
|
||||
var result = String(input);
|
||||
var padding = fill.repeat(Math.max(0, minLength - result.length));
|
||||
return `${padding}${result}`;
|
||||
}
|
||||
|
||||
function fraction(numerator, denominator) {
|
||||
const fdenominator = denominator + '';
|
||||
const fdenominator = String(denominator);
|
||||
const fnumerator = pad(numerator, fdenominator.length, ' ');
|
||||
return `${fnumerator}/${fdenominator}`;
|
||||
}
|
||||
@ -100,11 +101,12 @@ class BenchmarkProgress {
|
||||
const percent = pad(Math.floor(completedRate * 100), 3, ' ');
|
||||
|
||||
const caption = finished ? 'Done\n' : this.currentFile;
|
||||
return `[${getTime(diff)}|% ${percent}` +
|
||||
`| ${fraction(completedFiles, scheduledFiles)} files ` +
|
||||
`| ${fraction(completedRunsForFile, runsPerFile)} runs ` +
|
||||
`| ${fraction(completedConfig, scheduledConfig)} configs]` +
|
||||
`: ${caption} `;
|
||||
return `[${getTime(diff)}|% ${
|
||||
percent}| ${
|
||||
fraction(completedFiles, scheduledFiles)} files | ${
|
||||
fraction(completedRunsForFile, runsPerFile)} runs | ${
|
||||
fraction(completedConfig, scheduledConfig)} configs]: ${
|
||||
caption} `;
|
||||
}
|
||||
|
||||
updateProgress(finished) {
|
||||
|
@ -4,6 +4,9 @@ const child_process = require('child_process');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const requirementsURL =
|
||||
'https://github.com/nodejs/node/blob/master/doc/guides/writing-and-running-benchmarks.md##http-benchmark-requirements';
|
||||
|
||||
// The port used by servers and wrk
|
||||
exports.PORT = process.env.PORT || 12346;
|
||||
|
||||
@ -133,20 +136,19 @@ exports.run = function(options, callback) {
|
||||
benchmarker: exports.default_http_benchmarker
|
||||
}, options);
|
||||
if (!options.benchmarker) {
|
||||
callback(new Error('Could not locate required http benchmarker. See ' +
|
||||
'https://github.com/nodejs/node/blob/master/doc/guides/writing-and-running-benchmarks.md##http-benchmark-requirements ' +
|
||||
'for further instructions.'));
|
||||
callback(new Error(`Could not locate required http benchmarker. See ${
|
||||
requirementsURL} for further instructions.`));
|
||||
return;
|
||||
}
|
||||
const benchmarker = benchmarkers[options.benchmarker];
|
||||
if (!benchmarker) {
|
||||
callback(new Error(`Requested benchmarker '${options.benchmarker}' is ` +
|
||||
'not supported'));
|
||||
callback(new Error(`Requested benchmarker '${
|
||||
options.benchmarker}' is not supported`));
|
||||
return;
|
||||
}
|
||||
if (!benchmarker.present) {
|
||||
callback(new Error(`Requested benchmarker '${options.benchmarker}' is ` +
|
||||
'not installed'));
|
||||
callback(new Error(`Requested benchmarker '${
|
||||
options.benchmarker}' is not installed`));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -172,8 +174,8 @@ exports.run = function(options, callback) {
|
||||
|
||||
const result = benchmarker.processResults(stdout);
|
||||
if (result === undefined) {
|
||||
callback(new Error(`${options.benchmarker} produced strange output: ` +
|
||||
stdout, code));
|
||||
callback(new Error(
|
||||
`${options.benchmarker} produced strange output: ${stdout}`, code));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,17 @@
|
||||
const common = require('../common.js');
|
||||
const assert = require('assert');
|
||||
const bench = common.createBenchmark(main, {
|
||||
type: ('Int8Array Uint8Array Int16Array Uint16Array Int32Array Uint32Array ' +
|
||||
'Float32Array Float64Array Uint8ClampedArray').split(' '),
|
||||
type: [
|
||||
'Int8Array',
|
||||
'Uint8Array',
|
||||
'Int16Array',
|
||||
'Uint16Array',
|
||||
'Int32Array',
|
||||
'Uint32Array',
|
||||
'Float32Array',
|
||||
'Float64Array',
|
||||
'Uint8ClampedArray',
|
||||
],
|
||||
n: [1],
|
||||
method: ['strict', 'nonstrict'],
|
||||
len: [1e6]
|
||||
|
@ -12,7 +12,7 @@ function main(conf) {
|
||||
const linesCount = 8 << 16;
|
||||
const bytesCount = charsPerLine * linesCount / 4 * 3;
|
||||
|
||||
const line = 'abcd'.repeat(charsPerLine / 4) + '\n';
|
||||
const line = `${'abcd'.repeat(charsPerLine / 4)}\n`;
|
||||
const data = line.repeat(linesCount);
|
||||
// eslint-disable-next-line no-unescaped-regexp-dot
|
||||
data.match(/./); // Flatten the string
|
||||
|
@ -28,7 +28,7 @@ function main(conf) {
|
||||
} else {
|
||||
for (var string of chars) {
|
||||
// Strings must be built differently, depending on encoding
|
||||
var data = buildString(string, len);
|
||||
var data = string.repeat(len);
|
||||
if (encoding === 'utf8') {
|
||||
strings.push(data);
|
||||
} else if (encoding === 'base64') {
|
||||
@ -54,9 +54,3 @@ function main(conf) {
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
function buildString(str, times) {
|
||||
if (times === 1) return str;
|
||||
|
||||
return str + buildString(str, times - 1);
|
||||
}
|
||||
|
@ -30,14 +30,14 @@ function main(conf) {
|
||||
var len = +conf.millions * 1e6;
|
||||
var clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
|
||||
var buff = new clazz(8);
|
||||
var fn = 'read' + conf.type;
|
||||
var fn = `read${conf.type}`;
|
||||
|
||||
buff.writeDoubleLE(0, 0, noAssert);
|
||||
var testFunction = new Function('buff', [
|
||||
'for (var i = 0; i !== ' + len + '; i++) {',
|
||||
' buff.' + fn + '(0, ' + JSON.stringify(noAssert) + ');',
|
||||
'}'
|
||||
].join('\n'));
|
||||
var testFunction = new Function('buff', `
|
||||
for (var i = 0; i !== ${len}; i++) {
|
||||
buff.${fn}(0, ${JSON.stringify(noAssert)});
|
||||
}
|
||||
`);
|
||||
bench.start();
|
||||
testFunction(buff);
|
||||
bench.end(len / 1e6);
|
||||
|
@ -64,11 +64,11 @@ function createBuffer(len, aligned) {
|
||||
}
|
||||
|
||||
function genMethod(method) {
|
||||
const fnString =
|
||||
'return function ' + method + '(n, buf) {' +
|
||||
' for (var i = 0; i <= n; i++)' +
|
||||
' buf.' + method + '();' +
|
||||
'}';
|
||||
const fnString = `
|
||||
return function ${method}(n, buf) {
|
||||
for (var i = 0; i <= n; i++)
|
||||
buf.${method}();
|
||||
}`;
|
||||
return (new Function(fnString))();
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ function main(conf) {
|
||||
var len = +conf.millions * 1e6;
|
||||
var clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
|
||||
var buff = new clazz(8);
|
||||
var fn = 'write' + conf.type;
|
||||
var fn = `write${conf.type}`;
|
||||
|
||||
if (fn.match(/Int/))
|
||||
benchInt(buff, fn, len, noAssert);
|
||||
@ -60,22 +60,22 @@ function main(conf) {
|
||||
|
||||
function benchInt(buff, fn, len, noAssert) {
|
||||
var m = mod[fn];
|
||||
var testFunction = new Function('buff', [
|
||||
'for (var i = 0; i !== ' + len + '; i++) {',
|
||||
' buff.' + fn + '(i & ' + m + ', 0, ' + JSON.stringify(noAssert) + ');',
|
||||
'}'
|
||||
].join('\n'));
|
||||
var testFunction = new Function('buff', `
|
||||
for (var i = 0; i !== ${len}; i++) {
|
||||
buff.${fn}(i & ${m}, 0, ${JSON.stringify(noAssert)});
|
||||
}
|
||||
`);
|
||||
bench.start();
|
||||
testFunction(buff);
|
||||
bench.end(len / 1e6);
|
||||
}
|
||||
|
||||
function benchFloat(buff, fn, len, noAssert) {
|
||||
var testFunction = new Function('buff', [
|
||||
'for (var i = 0; i !== ' + len + '; i++) {',
|
||||
' buff.' + fn + '(i, 0, ' + JSON.stringify(noAssert) + ');',
|
||||
'}'
|
||||
].join('\n'));
|
||||
var testFunction = new Function('buff', `
|
||||
for (var i = 0; i !== ${len}; i++) {
|
||||
buff.${fn}(i, 0, ${JSON.stringify(noAssert)});
|
||||
}
|
||||
`);
|
||||
bench.start();
|
||||
testFunction(buff);
|
||||
bench.end(len / 1e6);
|
||||
|
@ -44,7 +44,7 @@ function main(conf) {
|
||||
var ab = new ArrayBuffer(8);
|
||||
var dv = new DataView(ab, 0, 8);
|
||||
var le = /LE$/.test(conf.type);
|
||||
var fn = 'set' + conf.type.replace(/[LB]E$/, '');
|
||||
var fn = `set${conf.type.replace(/[LB]E$/, '')}`;
|
||||
|
||||
if (/int/i.test(fn))
|
||||
benchInt(dv, fn, len, le);
|
||||
|
@ -44,7 +44,7 @@ Benchmark.prototype._parseArgs = function(argv, configs) {
|
||||
for (const arg of argv) {
|
||||
const match = arg.match(/^(.+?)=([\s\S]*)$/);
|
||||
if (!match) {
|
||||
console.error('bad argument: ' + arg);
|
||||
console.error(`bad argument: ${arg}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const config = match[1];
|
||||
@ -206,7 +206,7 @@ function formatResult(data) {
|
||||
// Construct configuration string, " A=a, B=b, ..."
|
||||
let conf = '';
|
||||
for (const key of Object.keys(data.conf)) {
|
||||
conf += ' ' + key + '=' + JSON.stringify(data.conf[key]);
|
||||
conf += ` ${key}=${JSON.stringify(data.conf[key])}`;
|
||||
}
|
||||
|
||||
var rate = data.rate.toString().split('.');
|
||||
|
@ -79,14 +79,14 @@ if (showProgress) {
|
||||
// Construct configuration string, " A=a, B=b, ..."
|
||||
let conf = '';
|
||||
for (const key of Object.keys(data.conf)) {
|
||||
conf += ' ' + key + '=' + JSON.stringify(data.conf[key]);
|
||||
conf += ` ${key}=${JSON.stringify(data.conf[key])}`;
|
||||
}
|
||||
conf = conf.slice(1);
|
||||
// Escape quotes (") for correct csv formatting
|
||||
conf = conf.replace(/"/g, '""');
|
||||
|
||||
console.log(`"${job.binary}", "${job.filename}", "${conf}", ` +
|
||||
`${data.rate}, ${data.time}`);
|
||||
console.log(`"${job.binary}", "${job.filename}", "${conf}", ${
|
||||
data.rate}, ${data.time}`);
|
||||
if (showProgress) {
|
||||
// One item in the subqueue has been completed.
|
||||
progress.completeConfig(data);
|
||||
|
@ -51,7 +51,7 @@ function main(conf) {
|
||||
message = Buffer.alloc(conf.len, 'b');
|
||||
break;
|
||||
default:
|
||||
throw new Error('unknown message type: ' + conf.type);
|
||||
throw new Error(`unknown message type: ${conf.type}`);
|
||||
}
|
||||
|
||||
var fn = api === 'stream' ? streamWrite : legacyWrite;
|
||||
|
@ -36,7 +36,7 @@ function main(conf) {
|
||||
message = Buffer.alloc(conf.len, 'b');
|
||||
break;
|
||||
default:
|
||||
throw new Error('unknown message type: ' + conf.type);
|
||||
throw new Error(`unknown message type: ${conf.type}`);
|
||||
}
|
||||
|
||||
var fn = api === 'stream' ? streamWrite : legacyWrite;
|
||||
|
@ -35,7 +35,7 @@ function main(conf) {
|
||||
message = Buffer.alloc(conf.len, 'b');
|
||||
break;
|
||||
default:
|
||||
throw new Error('unknown message type: ' + conf.type);
|
||||
throw new Error(`unknown message type: ${conf.type}`);
|
||||
}
|
||||
|
||||
var fn = api === 'stream' ? streamWrite : legacyWrite;
|
||||
|
@ -10,10 +10,10 @@ var RSA_PublicPem = {};
|
||||
var RSA_PrivatePem = {};
|
||||
|
||||
keylen_list.forEach(function(key) {
|
||||
RSA_PublicPem[key] = fs.readFileSync(fixtures_keydir +
|
||||
'/rsa_public_' + key + '.pem');
|
||||
RSA_PrivatePem[key] = fs.readFileSync(fixtures_keydir +
|
||||
'/rsa_private_' + key + '.pem');
|
||||
RSA_PublicPem[key] =
|
||||
fs.readFileSync(`${fixtures_keydir}/rsa_public_${key}.pem`);
|
||||
RSA_PrivatePem[key] =
|
||||
fs.readFileSync(`${fixtures_keydir}/rsa_private_${key}.pem`);
|
||||
});
|
||||
|
||||
var bench = common.createBenchmark(main, {
|
||||
|
@ -10,10 +10,10 @@ var RSA_PublicPem = {};
|
||||
var RSA_PrivatePem = {};
|
||||
|
||||
keylen_list.forEach(function(key) {
|
||||
RSA_PublicPem[key] = fs.readFileSync(fixtures_keydir +
|
||||
'/rsa_public_' + key + '.pem');
|
||||
RSA_PrivatePem[key] = fs.readFileSync(fixtures_keydir +
|
||||
'/rsa_private_' + key + '.pem');
|
||||
RSA_PublicPem[key] =
|
||||
fs.readFileSync(`${fixtures_keydir}/rsa_public_${key}.pem`);
|
||||
RSA_PrivatePem[key] =
|
||||
fs.readFileSync(`${fixtures_keydir}/rsa_private_${key}.pem`);
|
||||
});
|
||||
|
||||
var bench = common.createBenchmark(main, {
|
||||
|
@ -16,11 +16,11 @@ function runObject(n) {
|
||||
var i = 0;
|
||||
bench.start();
|
||||
for (; i < n; i++) {
|
||||
m['i' + i] = i;
|
||||
m['s' + i] = String(i);
|
||||
assert.strictEqual(String(m['i' + i]), m['s' + i]);
|
||||
m['i' + i] = undefined;
|
||||
m['s' + i] = undefined;
|
||||
m[`i${i}`] = i;
|
||||
m[`s${i}`] = String(i);
|
||||
assert.strictEqual(String(m[`i${i}`]), m[`s${i}`]);
|
||||
m[`i${i}`] = undefined;
|
||||
m[`s${i}`] = undefined;
|
||||
}
|
||||
bench.end(n / 1e6);
|
||||
}
|
||||
@ -30,11 +30,11 @@ function runNullProtoObject(n) {
|
||||
var i = 0;
|
||||
bench.start();
|
||||
for (; i < n; i++) {
|
||||
m['i' + i] = i;
|
||||
m['s' + i] = String(i);
|
||||
assert.strictEqual(String(m['i' + i]), m['s' + i]);
|
||||
m['i' + i] = undefined;
|
||||
m['s' + i] = undefined;
|
||||
m[`i${i}`] = i;
|
||||
m[`s${i}`] = String(i);
|
||||
assert.strictEqual(String(m[`i${i}`]), m[`s${i}`]);
|
||||
m[`i${i}`] = undefined;
|
||||
m[`s${i}`] = undefined;
|
||||
}
|
||||
bench.end(n / 1e6);
|
||||
}
|
||||
@ -44,11 +44,11 @@ function runNullProtoLiteralObject(n) {
|
||||
var i = 0;
|
||||
bench.start();
|
||||
for (; i < n; i++) {
|
||||
m['i' + i] = i;
|
||||
m['s' + i] = String(i);
|
||||
assert.strictEqual(String(m['i' + i]), m['s' + i]);
|
||||
m['i' + i] = undefined;
|
||||
m['s' + i] = undefined;
|
||||
m[`i${i}`] = i;
|
||||
m[`s${i}`] = String(i);
|
||||
assert.strictEqual(String(m[`i${i}`]), m[`s${i}`]);
|
||||
m[`i${i}`] = undefined;
|
||||
m[`s${i}`] = undefined;
|
||||
}
|
||||
bench.end(n / 1e6);
|
||||
}
|
||||
@ -61,11 +61,11 @@ function runStorageObject(n) {
|
||||
var i = 0;
|
||||
bench.start();
|
||||
for (; i < n; i++) {
|
||||
m['i' + i] = i;
|
||||
m['s' + i] = String(i);
|
||||
assert.strictEqual(String(m['i' + i]), m['s' + i]);
|
||||
m['i' + i] = undefined;
|
||||
m['s' + i] = undefined;
|
||||
m[`i${i}`] = i;
|
||||
m[`s${i}`] = String(i);
|
||||
assert.strictEqual(String(m[`i${i}`]), m[`s${i}`]);
|
||||
m[`i${i}`] = undefined;
|
||||
m[`s${i}`] = undefined;
|
||||
}
|
||||
bench.end(n / 1e6);
|
||||
}
|
||||
@ -73,10 +73,10 @@ function runStorageObject(n) {
|
||||
function fakeMap() {
|
||||
const m = {};
|
||||
return {
|
||||
get(key) { return m['$' + key]; },
|
||||
set(key, val) { m['$' + key] = val; },
|
||||
get(key) { return m[`$${key}`]; },
|
||||
set(key, val) { m[`$${key}`] = val; },
|
||||
get size() { return Object.keys(m).length; },
|
||||
has(key) { return Object.prototype.hasOwnProperty.call(m, '$' + key); }
|
||||
has(key) { return Object.prototype.hasOwnProperty.call(m, `$${key}`); }
|
||||
};
|
||||
}
|
||||
|
||||
@ -85,11 +85,11 @@ function runFakeMap(n) {
|
||||
var i = 0;
|
||||
bench.start();
|
||||
for (; i < n; i++) {
|
||||
m.set('i' + i, i);
|
||||
m.set('s' + i, String(i));
|
||||
assert.strictEqual(String(m.get('i' + i)), m.get('s' + i));
|
||||
m.set('i' + i, undefined);
|
||||
m.set('s' + i, undefined);
|
||||
m.set(`i${i}`, i);
|
||||
m.set(`s${i}`, String(i));
|
||||
assert.strictEqual(String(m.get(`i${i}`)), m.get(`s${i}`));
|
||||
m.set(`i${i}`, undefined);
|
||||
m.set(`s${i}`, undefined);
|
||||
}
|
||||
bench.end(n / 1e6);
|
||||
}
|
||||
@ -99,11 +99,11 @@ function runMap(n) {
|
||||
var i = 0;
|
||||
bench.start();
|
||||
for (; i < n; i++) {
|
||||
m.set('i' + i, i);
|
||||
m.set('s' + i, String(i));
|
||||
assert.strictEqual(String(m.get('i' + i)), m.get('s' + i));
|
||||
m.set('i' + i, undefined);
|
||||
m.set('s' + i, undefined);
|
||||
m.set(`i${i}`, i);
|
||||
m.set(`s${i}`, String(i));
|
||||
assert.strictEqual(String(m.get(`i${i}`)), m.get(`s${i}`));
|
||||
m.set(`i${i}`, undefined);
|
||||
m.set(`s${i}`, undefined);
|
||||
}
|
||||
bench.end(n / 1e6);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ function main(conf) {
|
||||
else if (type === 'resolved')
|
||||
resolvedPath(n);
|
||||
else
|
||||
throw new Error('unknown "type": ' + type);
|
||||
throw new Error(`unknown "type": ${type}`);
|
||||
}
|
||||
|
||||
function relativePath(n) {
|
||||
|
@ -24,7 +24,7 @@ function main(conf) {
|
||||
else if (type === 'resolved')
|
||||
resolvedPath(n);
|
||||
else
|
||||
throw new Error('unknown "type": ' + type);
|
||||
throw new Error(`unknown "type": ${type}`);
|
||||
bench.end(n);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ function main(conf) {
|
||||
for (var i = 0; i < extra_header_count; i++) {
|
||||
// Utilize first three powers of a small integer for an odd cycle and
|
||||
// because the fourth power of some integers overloads the server.
|
||||
todo.push('X-Header-' + i + ': ' + headers[i % 3]);
|
||||
todo.push(`X-Header-${i}: ${headers[i % 3]}`);
|
||||
}
|
||||
todo.push('');
|
||||
todo.push('');
|
||||
|
@ -27,7 +27,7 @@ function main(conf) {
|
||||
return;
|
||||
|
||||
setTimeout(function() {
|
||||
var path = '/' + conf.type + '/' + conf.len;
|
||||
var path = `/${conf.type}/${conf.len}`;
|
||||
|
||||
bench.http({
|
||||
path: path,
|
||||
|
@ -6,7 +6,7 @@ var fs = require('fs');
|
||||
var fork = require('child_process').fork;
|
||||
var common = require('../common.js');
|
||||
var test = require('../../test/common.js');
|
||||
var pep = path.dirname(process.argv[1]) + '/_chunky_http_client.js';
|
||||
var pep = `${path.dirname(process.argv[1])}/_chunky_http_client.js`;
|
||||
var PIPE = test.PIPE;
|
||||
|
||||
try {
|
||||
@ -30,7 +30,7 @@ server = http.createServer(function(req, res) {
|
||||
});
|
||||
|
||||
server.on('error', function(err) {
|
||||
throw new Error('server error: ' + err);
|
||||
throw new Error(`server error: ${err}`);
|
||||
});
|
||||
|
||||
server.listen(PIPE);
|
||||
|
@ -16,8 +16,7 @@ function main(conf) {
|
||||
var server = require('../fixtures/simple-http-server.js')
|
||||
.listen(process.env.PORT || common.PORT)
|
||||
.on('listening', function() {
|
||||
var path = '/' + conf.type + '/' + conf.len + '/' + conf.chunks + '/' +
|
||||
conf.res;
|
||||
var path = `/${conf.type}/${conf.len}/${conf.chunks}/${conf.res}`;
|
||||
|
||||
bench.http({
|
||||
path: path,
|
||||
|
@ -21,7 +21,7 @@ var bench = common.createBenchmark(main, {
|
||||
const nullStream = createNullStream();
|
||||
|
||||
function usingRestAndConcat(...args) {
|
||||
nullStream.write('this is ' + args[0] + ' of ' + args[1] + '\n');
|
||||
nullStream.write(`this is ${args[0]} of ${args[1]}\n`);
|
||||
}
|
||||
|
||||
function usingRestAndSpreadTS(...args) {
|
||||
@ -37,15 +37,15 @@ function usingArgumentsAndApplyTS() {
|
||||
}
|
||||
|
||||
function usingRestAndSpreadC(...args) {
|
||||
nullStream.write(util.format(...args) + '\n');
|
||||
nullStream.write(`${util.format(...args)}\n`);
|
||||
}
|
||||
|
||||
function usingRestAndApplyC(...args) {
|
||||
nullStream.write(util.format.apply(null, args) + '\n');
|
||||
nullStream.write(`${util.format.apply(null, args)}\n`);
|
||||
}
|
||||
|
||||
function usingArgumentsAndApplyC() {
|
||||
nullStream.write(util.format.apply(null, arguments) + '\n');
|
||||
nullStream.write(`${util.format.apply(null, arguments)}\n`);
|
||||
}
|
||||
|
||||
function runUsingRestAndConcat(n) {
|
||||
|
@ -9,8 +9,8 @@ var dir = path.join(__dirname, '..', '..', 'deps', 'v8', 'benchmarks');
|
||||
|
||||
function load(filename, inGlobal) {
|
||||
var source = fs.readFileSync(path.join(dir, filename), 'utf8');
|
||||
if (!inGlobal) source = '(function () {' + source + '\n})()';
|
||||
vm.runInThisContext(source, { filename: 'v8/bechmark/' + filename });
|
||||
if (!inGlobal) source = `(function () {${source}\n})()`;
|
||||
vm.runInThisContext(source, { filename: `v8/bechmark/${filename}` });
|
||||
}
|
||||
|
||||
load('base.js', true);
|
||||
@ -41,13 +41,13 @@ global.BenchmarkSuite.RunSuites({
|
||||
});
|
||||
},
|
||||
NotifyError: function(name, error) {
|
||||
console.error(name + ': ' + error);
|
||||
console.error(`${name}: ${error}`);
|
||||
},
|
||||
NotifyScore: function(score) {
|
||||
common.sendResult({
|
||||
name: benchmark_name,
|
||||
conf: {
|
||||
benchmark: 'Score (version ' + global.BenchmarkSuite.version + ')'
|
||||
benchmark: `Score (version ${global.BenchmarkSuite.version})`
|
||||
},
|
||||
rate: score,
|
||||
time: 0
|
||||
|
@ -20,13 +20,13 @@ function main(conf) {
|
||||
try { fs.mkdirSync(benchmarkDirectory); } catch (e) {}
|
||||
|
||||
for (var i = 0; i <= n; i++) {
|
||||
fs.mkdirSync(benchmarkDirectory + i);
|
||||
fs.mkdirSync(`${benchmarkDirectory}${i}`);
|
||||
fs.writeFileSync(
|
||||
benchmarkDirectory + i + '/package.json',
|
||||
`${benchmarkDirectory}${i}/package.json`,
|
||||
'{"main": "index.js"}'
|
||||
);
|
||||
fs.writeFileSync(
|
||||
benchmarkDirectory + i + '/index.js',
|
||||
`${benchmarkDirectory}${i}/index.js`,
|
||||
'module.exports = "";'
|
||||
);
|
||||
}
|
||||
@ -43,12 +43,12 @@ function measureFull(n, useCache) {
|
||||
var i;
|
||||
if (useCache) {
|
||||
for (i = 0; i <= n; i++) {
|
||||
require(benchmarkDirectory + i + '/index.js');
|
||||
require(`${benchmarkDirectory}${i}/index.js`);
|
||||
}
|
||||
}
|
||||
bench.start();
|
||||
for (i = 0; i <= n; i++) {
|
||||
require(benchmarkDirectory + i + '/index.js');
|
||||
require(`${benchmarkDirectory}${i}/index.js`);
|
||||
}
|
||||
bench.end(n / 1e3);
|
||||
}
|
||||
@ -57,12 +57,12 @@ function measureDir(n, useCache) {
|
||||
var i;
|
||||
if (useCache) {
|
||||
for (i = 0; i <= n; i++) {
|
||||
require(benchmarkDirectory + i);
|
||||
require(`${benchmarkDirectory}${i}`);
|
||||
}
|
||||
}
|
||||
bench.start();
|
||||
for (i = 0; i <= n; i++) {
|
||||
require(benchmarkDirectory + i);
|
||||
require(`${benchmarkDirectory}${i}`);
|
||||
}
|
||||
bench.end(n / 1e3);
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ function main(conf) {
|
||||
chunk = 'x'.repeat(len);
|
||||
break;
|
||||
default:
|
||||
throw new Error('invalid type: ' + type);
|
||||
throw new Error(`invalid type: ${type}`);
|
||||
}
|
||||
|
||||
server();
|
||||
|
@ -34,7 +34,7 @@ function main(conf) {
|
||||
chunk = 'x'.repeat(len);
|
||||
break;
|
||||
default:
|
||||
throw new Error('invalid type: ' + type);
|
||||
throw new Error(`invalid type: ${type}`);
|
||||
}
|
||||
|
||||
server();
|
||||
|
@ -34,7 +34,7 @@ function main(conf) {
|
||||
chunk = 'x'.repeat(len);
|
||||
break;
|
||||
default:
|
||||
throw new Error('invalid type: ' + type);
|
||||
throw new Error(`invalid type: ${type}`);
|
||||
}
|
||||
|
||||
server();
|
||||
|
@ -34,7 +34,7 @@ function main(conf) {
|
||||
chunk = 'x'.repeat(len);
|
||||
break;
|
||||
default:
|
||||
throw new Error('invalid type: ' + type);
|
||||
throw new Error(`invalid type: ${type}`);
|
||||
}
|
||||
|
||||
server();
|
||||
|
@ -89,7 +89,7 @@ function client() {
|
||||
chunk = 'x'.repeat(len);
|
||||
break;
|
||||
default:
|
||||
throw new Error('invalid type: ' + type);
|
||||
throw new Error(`invalid type: ${type}`);
|
||||
}
|
||||
|
||||
var clientHandle = new TCP();
|
||||
|
@ -86,7 +86,7 @@ function client() {
|
||||
chunk = 'x'.repeat(len);
|
||||
break;
|
||||
default:
|
||||
throw new Error('invalid type: ' + type);
|
||||
throw new Error(`invalid type: ${type}`);
|
||||
}
|
||||
|
||||
var clientHandle = new TCP();
|
||||
|
@ -60,7 +60,7 @@ function server() {
|
||||
chunk = 'x'.repeat(len);
|
||||
break;
|
||||
default:
|
||||
throw new Error('invalid type: ' + type);
|
||||
throw new Error(`invalid type: ${type}`);
|
||||
}
|
||||
|
||||
clientHandle.readStart();
|
||||
|
@ -21,7 +21,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.posix;
|
||||
var input = '' + conf.pathext;
|
||||
var input = String(conf.pathext);
|
||||
var ext;
|
||||
var extIdx = input.indexOf('|');
|
||||
if (extIdx !== -1) {
|
||||
|
@ -21,7 +21,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.win32;
|
||||
var input = '' + conf.pathext;
|
||||
var input = String(conf.pathext);
|
||||
var ext;
|
||||
var extIdx = input.indexOf('|');
|
||||
if (extIdx !== -1) {
|
||||
|
@ -18,7 +18,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.posix;
|
||||
var input = '' + conf.path;
|
||||
var input = String(conf.path);
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
|
@ -18,7 +18,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.win32;
|
||||
var input = '' + conf.path;
|
||||
var input = String(conf.path);
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
|
@ -21,7 +21,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.posix;
|
||||
var input = '' + conf.path;
|
||||
var input = String(conf.path);
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
|
@ -21,7 +21,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.win32;
|
||||
var input = '' + conf.path;
|
||||
var input = String(conf.path);
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
|
@ -12,7 +12,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.posix;
|
||||
var props = ('' + conf.props).split('|');
|
||||
var props = String(conf.props).split('|');
|
||||
var obj = {
|
||||
root: props[0] || '',
|
||||
dir: props[1] || '',
|
||||
|
@ -12,7 +12,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.win32;
|
||||
var props = ('' + conf.props).split('|');
|
||||
var props = String(conf.props).split('|');
|
||||
var obj = {
|
||||
root: props[0] || '',
|
||||
dir: props[1] || '',
|
||||
|
@ -16,7 +16,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.posix;
|
||||
var input = '' + conf.path;
|
||||
var input = String(conf.path);
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
|
@ -17,7 +17,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.win32;
|
||||
var input = '' + conf.path;
|
||||
var input = String(conf.path);
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
|
@ -12,7 +12,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.posix;
|
||||
var args = ('' + conf.paths).split('|');
|
||||
var args = String(conf.paths).split('|');
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
|
@ -12,7 +12,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.win32;
|
||||
var args = ('' + conf.paths).split('|');
|
||||
var args = String(conf.paths).split('|');
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
|
@ -15,7 +15,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.win32;
|
||||
var input = '' + conf.path;
|
||||
var input = String(conf.path);
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
|
@ -17,7 +17,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.posix;
|
||||
var input = '' + conf.path;
|
||||
var input = String(conf.path);
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
|
@ -17,7 +17,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.win32;
|
||||
var input = '' + conf.path;
|
||||
var input = String(conf.path);
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
|
@ -18,7 +18,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.posix;
|
||||
var input = '' + conf.path;
|
||||
var input = String(conf.path);
|
||||
|
||||
for (var i = 0; i < n; i++) {
|
||||
p.parse(input);
|
||||
|
@ -19,7 +19,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.win32;
|
||||
var input = '' + conf.path;
|
||||
var input = String(conf.path);
|
||||
|
||||
for (var i = 0; i < n; i++) {
|
||||
p.parse(input);
|
||||
|
@ -18,7 +18,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.posix;
|
||||
var from = '' + conf.paths;
|
||||
var from = String(conf.paths);
|
||||
var to = '';
|
||||
var delimIdx = from.indexOf('|');
|
||||
if (delimIdx > -1) {
|
||||
|
@ -16,7 +16,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.win32;
|
||||
var from = '' + conf.paths;
|
||||
var from = String(conf.paths);
|
||||
var to = '';
|
||||
var delimIdx = from.indexOf('|');
|
||||
if (delimIdx > -1) {
|
||||
|
@ -15,7 +15,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.posix;
|
||||
var args = ('' + conf.paths).split('|');
|
||||
var args = String(conf.paths).split('|');
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
|
@ -15,7 +15,7 @@ var bench = common.createBenchmark(main, {
|
||||
function main(conf) {
|
||||
var n = +conf.n;
|
||||
var p = path.win32;
|
||||
var args = ('' + conf.paths).split('|');
|
||||
var args = String(conf.paths).split('|');
|
||||
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i++) {
|
||||
|
@ -50,7 +50,7 @@ if (format === 'csv') {
|
||||
// Construct configuration string, " A=a, B=b, ..."
|
||||
let conf = '';
|
||||
for (const key of Object.keys(data.conf)) {
|
||||
conf += ' ' + key + '=' + JSON.stringify(data.conf[key]);
|
||||
conf += ` ${key}=${JSON.stringify(data.conf[key])}`;
|
||||
}
|
||||
// delete first space of the configuration
|
||||
conf = conf.slice(1);
|
||||
|
@ -34,7 +34,7 @@ function csvEncodeValue(value) {
|
||||
if (typeof value === 'number') {
|
||||
return value.toString();
|
||||
} else {
|
||||
return '"' + value.replace(/"/g, '""') + '"';
|
||||
return `"${value.replace(/"/g, '""')}"`;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,5 +22,5 @@ function main(conf) {
|
||||
}
|
||||
|
||||
function cb() {
|
||||
assert(false, 'Timer ' + this._idleTimeout + ' should not call callback');
|
||||
assert(false, `Timer ${this._idleTimeout} should not call callback`);
|
||||
}
|
||||
|
@ -23,5 +23,5 @@ function main(conf) {
|
||||
}
|
||||
|
||||
function cb() {
|
||||
assert(false, 'Timer ' + this._idleTimeout + ' should not call callback');
|
||||
assert(false, `Timer ${this._idleTimeout} should not call callback`);
|
||||
}
|
||||
|
@ -38,9 +38,9 @@ function main(conf) {
|
||||
}
|
||||
|
||||
options = {
|
||||
key: fs.readFileSync(cert_dir + '/test_key.pem'),
|
||||
cert: fs.readFileSync(cert_dir + '/test_cert.pem'),
|
||||
ca: [ fs.readFileSync(cert_dir + '/test_ca.pem') ],
|
||||
key: fs.readFileSync(`${cert_dir}/test_key.pem`),
|
||||
cert: fs.readFileSync(`${cert_dir}/test_cert.pem`),
|
||||
ca: [ fs.readFileSync(`${cert_dir}/test_ca.pem`) ],
|
||||
ciphers: 'AES256-GCM-SHA384'
|
||||
};
|
||||
|
||||
|
@ -22,9 +22,9 @@ function main(conf) {
|
||||
|
||||
var cert_dir = path.resolve(__dirname, '../../test/fixtures');
|
||||
var options = {
|
||||
key: fs.readFileSync(cert_dir + '/test_key.pem'),
|
||||
cert: fs.readFileSync(cert_dir + '/test_cert.pem'),
|
||||
ca: [ fs.readFileSync(cert_dir + '/test_ca.pem') ],
|
||||
key: fs.readFileSync(`${cert_dir}/test_key.pem`),
|
||||
cert: fs.readFileSync(`${cert_dir}/test_cert.pem`),
|
||||
ca: [ fs.readFileSync(`${cert_dir}/test_ca.pem`) ],
|
||||
ciphers: 'AES256-GCM-SHA384'
|
||||
};
|
||||
|
||||
|
@ -48,7 +48,7 @@ function useWHATWG(n, input) {
|
||||
var obj = new URL(input);
|
||||
var noDead = {
|
||||
protocol: obj.protocol,
|
||||
auth: obj.username + ':' + obj.password,
|
||||
auth: `${obj.username}:${obj.password}`,
|
||||
host: obj.host,
|
||||
hostname: obj.hostname,
|
||||
port: obj.port,
|
||||
@ -59,7 +59,7 @@ function useWHATWG(n, input) {
|
||||
bench.start();
|
||||
for (var i = 0; i < n; i += 1) {
|
||||
noDead.protocol = obj.protocol;
|
||||
noDead.auth = obj.username + ':' + obj.password;
|
||||
noDead.auth = `${obj.username}:${obj.password}`;
|
||||
noDead.host = obj.host;
|
||||
noDead.hostname = obj.hostname;
|
||||
noDead.port = obj.port;
|
||||
|
Loading…
x
Reference in New Issue
Block a user