Browse Source

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>
v6
Vse Mozhet Byt 8 years ago
parent
commit
22aa3d4899
  1. 18
      benchmark/_benchmark_progress.js
  2. 20
      benchmark/_http-benchmarkers.js
  3. 13
      benchmark/assert/deepequal-typedarrays.js
  4. 2
      benchmark/buffers/buffer-base64-decode-wrapped.js
  5. 8
      benchmark/buffers/buffer-bytelength.js
  6. 12
      benchmark/buffers/buffer-read.js
  7. 10
      benchmark/buffers/buffer-swap.js
  8. 22
      benchmark/buffers/buffer-write.js
  9. 2
      benchmark/buffers/dataview-set.js
  10. 4
      benchmark/common.js
  11. 6
      benchmark/compare.js
  12. 2
      benchmark/crypto/cipher-stream.js
  13. 2
      benchmark/crypto/hash-stream-creation.js
  14. 2
      benchmark/crypto/hash-stream-throughput.js
  15. 8
      benchmark/crypto/rsa-encrypt-decrypt-throughput.js
  16. 8
      benchmark/crypto/rsa-sign-verify-throughput.js
  17. 66
      benchmark/es/map-bench.js
  18. 2
      benchmark/fs/bench-realpath.js
  19. 2
      benchmark/fs/bench-realpathSync.js
  20. 2
      benchmark/http/_chunky_http_client.js
  21. 2
      benchmark/http/cluster.js
  22. 4
      benchmark/http/http_server_for_chunky_client.js
  23. 3
      benchmark/http/simple.js
  24. 8
      benchmark/misc/console.js
  25. 8
      benchmark/misc/v8-bench.js
  26. 14
      benchmark/module/module-loader.js
  27. 2
      benchmark/net/net-c2s-cork.js
  28. 2
      benchmark/net/net-c2s.js
  29. 2
      benchmark/net/net-pipe.js
  30. 2
      benchmark/net/net-s2c.js
  31. 2
      benchmark/net/tcp-raw-c2s.js
  32. 2
      benchmark/net/tcp-raw-pipe.js
  33. 2
      benchmark/net/tcp-raw-s2c.js
  34. 2
      benchmark/path/basename-posix.js
  35. 2
      benchmark/path/basename-win32.js
  36. 2
      benchmark/path/dirname-posix.js
  37. 2
      benchmark/path/dirname-win32.js
  38. 2
      benchmark/path/extname-posix.js
  39. 2
      benchmark/path/extname-win32.js
  40. 2
      benchmark/path/format-posix.js
  41. 2
      benchmark/path/format-win32.js
  42. 2
      benchmark/path/isAbsolute-posix.js
  43. 2
      benchmark/path/isAbsolute-win32.js
  44. 2
      benchmark/path/join-posix.js
  45. 2
      benchmark/path/join-win32.js
  46. 2
      benchmark/path/makeLong-win32.js
  47. 2
      benchmark/path/normalize-posix.js
  48. 2
      benchmark/path/normalize-win32.js
  49. 2
      benchmark/path/parse-posix.js
  50. 2
      benchmark/path/parse-win32.js
  51. 2
      benchmark/path/relative-posix.js
  52. 2
      benchmark/path/relative-win32.js
  53. 2
      benchmark/path/resolve-posix.js
  54. 2
      benchmark/path/resolve-win32.js
  55. 2
      benchmark/run.js
  56. 2
      benchmark/scatter.js
  57. 2
      benchmark/timers/timers-cancel-unpooled.js
  58. 2
      benchmark/timers/timers-insert-unpooled.js
  59. 6
      benchmark/tls/throughput.js
  60. 6
      benchmark/tls/tls-connect.js
  61. 4
      benchmark/url/legacy-vs-whatwg-url-get-prop.js

18
benchmark/_benchmark_progress.js

@ -3,12 +3,13 @@
const readline = require('readline'); const readline = require('readline');
function pad(input, minLength, fill) { function pad(input, minLength, fill) {
var result = input + ''; var result = String(input);
return fill.repeat(Math.max(0, minLength - result.length)) + result; var padding = fill.repeat(Math.max(0, minLength - result.length));
return `${padding}${result}`;
} }
function fraction(numerator, denominator) { function fraction(numerator, denominator) {
const fdenominator = denominator + ''; const fdenominator = String(denominator);
const fnumerator = pad(numerator, fdenominator.length, ' '); const fnumerator = pad(numerator, fdenominator.length, ' ');
return `${fnumerator}/${fdenominator}`; return `${fnumerator}/${fdenominator}`;
} }
@ -100,11 +101,12 @@ class BenchmarkProgress {
const percent = pad(Math.floor(completedRate * 100), 3, ' '); const percent = pad(Math.floor(completedRate * 100), 3, ' ');
const caption = finished ? 'Done\n' : this.currentFile; const caption = finished ? 'Done\n' : this.currentFile;
return `[${getTime(diff)}|% ${percent}` + return `[${getTime(diff)}|% ${
`| ${fraction(completedFiles, scheduledFiles)} files ` + percent}| ${
`| ${fraction(completedRunsForFile, runsPerFile)} runs ` + fraction(completedFiles, scheduledFiles)} files | ${
`| ${fraction(completedConfig, scheduledConfig)} configs]` + fraction(completedRunsForFile, runsPerFile)} runs | ${
`: ${caption} `; fraction(completedConfig, scheduledConfig)} configs]: ${
caption} `;
} }
updateProgress(finished) { updateProgress(finished) {

20
benchmark/_http-benchmarkers.js

@ -4,6 +4,9 @@ const child_process = require('child_process');
const path = require('path'); const path = require('path');
const fs = require('fs'); 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 // The port used by servers and wrk
exports.PORT = process.env.PORT || 12346; exports.PORT = process.env.PORT || 12346;
@ -133,20 +136,19 @@ exports.run = function(options, callback) {
benchmarker: exports.default_http_benchmarker benchmarker: exports.default_http_benchmarker
}, options); }, options);
if (!options.benchmarker) { if (!options.benchmarker) {
callback(new Error('Could not locate required http benchmarker. See ' + 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 ' + requirementsURL} for further instructions.`));
'for further instructions.'));
return; return;
} }
const benchmarker = benchmarkers[options.benchmarker]; const benchmarker = benchmarkers[options.benchmarker];
if (!benchmarker) { if (!benchmarker) {
callback(new Error(`Requested benchmarker '${options.benchmarker}' is ` + callback(new Error(`Requested benchmarker '${
'not supported')); options.benchmarker}' is not supported`));
return; return;
} }
if (!benchmarker.present) { if (!benchmarker.present) {
callback(new Error(`Requested benchmarker '${options.benchmarker}' is ` + callback(new Error(`Requested benchmarker '${
'not installed')); options.benchmarker}' is not installed`));
return; return;
} }
@ -172,8 +174,8 @@ exports.run = function(options, callback) {
const result = benchmarker.processResults(stdout); const result = benchmarker.processResults(stdout);
if (result === undefined) { if (result === undefined) {
callback(new Error(`${options.benchmarker} produced strange output: ` + callback(new Error(
stdout, code)); `${options.benchmarker} produced strange output: ${stdout}`, code));
return; return;
} }

13
benchmark/assert/deepequal-typedarrays.js

@ -2,8 +2,17 @@
const common = require('../common.js'); const common = require('../common.js');
const assert = require('assert'); const assert = require('assert');
const bench = common.createBenchmark(main, { const bench = common.createBenchmark(main, {
type: ('Int8Array Uint8Array Int16Array Uint16Array Int32Array Uint32Array ' + type: [
'Float32Array Float64Array Uint8ClampedArray').split(' '), 'Int8Array',
'Uint8Array',
'Int16Array',
'Uint16Array',
'Int32Array',
'Uint32Array',
'Float32Array',
'Float64Array',
'Uint8ClampedArray',
],
n: [1], n: [1],
method: ['strict', 'nonstrict'], method: ['strict', 'nonstrict'],
len: [1e6] len: [1e6]

2
benchmark/buffers/buffer-base64-decode-wrapped.js

@ -12,7 +12,7 @@ function main(conf) {
const linesCount = 8 << 16; const linesCount = 8 << 16;
const bytesCount = charsPerLine * linesCount / 4 * 3; 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); const data = line.repeat(linesCount);
// eslint-disable-next-line no-unescaped-regexp-dot // eslint-disable-next-line no-unescaped-regexp-dot
data.match(/./); // Flatten the string data.match(/./); // Flatten the string

8
benchmark/buffers/buffer-bytelength.js

@ -28,7 +28,7 @@ function main(conf) {
} else { } else {
for (var string of chars) { for (var string of chars) {
// Strings must be built differently, depending on encoding // Strings must be built differently, depending on encoding
var data = buildString(string, len); var data = string.repeat(len);
if (encoding === 'utf8') { if (encoding === 'utf8') {
strings.push(data); strings.push(data);
} else if (encoding === 'base64') { } else if (encoding === 'base64') {
@ -54,9 +54,3 @@ function main(conf) {
} }
bench.end(n); bench.end(n);
} }
function buildString(str, times) {
if (times === 1) return str;
return str + buildString(str, times - 1);
}

12
benchmark/buffers/buffer-read.js

@ -30,14 +30,14 @@ function main(conf) {
var len = +conf.millions * 1e6; var len = +conf.millions * 1e6;
var clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer; var clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
var buff = new clazz(8); var buff = new clazz(8);
var fn = 'read' + conf.type; var fn = `read${conf.type}`;
buff.writeDoubleLE(0, 0, noAssert); buff.writeDoubleLE(0, 0, noAssert);
var testFunction = new Function('buff', [ var testFunction = new Function('buff', `
'for (var i = 0; i !== ' + len + '; i++) {', for (var i = 0; i !== ${len}; i++) {
' buff.' + fn + '(0, ' + JSON.stringify(noAssert) + ');', buff.${fn}(0, ${JSON.stringify(noAssert)});
'}' }
].join('\n')); `);
bench.start(); bench.start();
testFunction(buff); testFunction(buff);
bench.end(len / 1e6); bench.end(len / 1e6);

10
benchmark/buffers/buffer-swap.js

@ -64,11 +64,11 @@ function createBuffer(len, aligned) {
} }
function genMethod(method) { function genMethod(method) {
const fnString = const fnString = `
'return function ' + method + '(n, buf) {' + return function ${method}(n, buf) {
' for (var i = 0; i <= n; i++)' + for (var i = 0; i <= n; i++)
' buf.' + method + '();' + buf.${method}();
'}'; }`;
return (new Function(fnString))(); return (new Function(fnString))();
} }

22
benchmark/buffers/buffer-write.js

@ -50,7 +50,7 @@ function main(conf) {
var len = +conf.millions * 1e6; var len = +conf.millions * 1e6;
var clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer; var clazz = conf.buf === 'fast' ? Buffer : require('buffer').SlowBuffer;
var buff = new clazz(8); var buff = new clazz(8);
var fn = 'write' + conf.type; var fn = `write${conf.type}`;
if (fn.match(/Int/)) if (fn.match(/Int/))
benchInt(buff, fn, len, noAssert); benchInt(buff, fn, len, noAssert);
@ -60,22 +60,22 @@ function main(conf) {
function benchInt(buff, fn, len, noAssert) { function benchInt(buff, fn, len, noAssert) {
var m = mod[fn]; var m = mod[fn];
var testFunction = new Function('buff', [ var testFunction = new Function('buff', `
'for (var i = 0; i !== ' + len + '; i++) {', for (var i = 0; i !== ${len}; i++) {
' buff.' + fn + '(i & ' + m + ', 0, ' + JSON.stringify(noAssert) + ');', buff.${fn}(i & ${m}, 0, ${JSON.stringify(noAssert)});
'}' }
].join('\n')); `);
bench.start(); bench.start();
testFunction(buff); testFunction(buff);
bench.end(len / 1e6); bench.end(len / 1e6);
} }
function benchFloat(buff, fn, len, noAssert) { function benchFloat(buff, fn, len, noAssert) {
var testFunction = new Function('buff', [ var testFunction = new Function('buff', `
'for (var i = 0; i !== ' + len + '; i++) {', for (var i = 0; i !== ${len}; i++) {
' buff.' + fn + '(i, 0, ' + JSON.stringify(noAssert) + ');', buff.${fn}(i, 0, ${JSON.stringify(noAssert)});
'}' }
].join('\n')); `);
bench.start(); bench.start();
testFunction(buff); testFunction(buff);
bench.end(len / 1e6); bench.end(len / 1e6);

2
benchmark/buffers/dataview-set.js

@ -44,7 +44,7 @@ function main(conf) {
var ab = new ArrayBuffer(8); var ab = new ArrayBuffer(8);
var dv = new DataView(ab, 0, 8); var dv = new DataView(ab, 0, 8);
var le = /LE$/.test(conf.type); 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)) if (/int/i.test(fn))
benchInt(dv, fn, len, le); benchInt(dv, fn, len, le);

4
benchmark/common.js

@ -44,7 +44,7 @@ Benchmark.prototype._parseArgs = function(argv, configs) {
for (const arg of argv) { for (const arg of argv) {
const match = arg.match(/^(.+?)=([\s\S]*)$/); const match = arg.match(/^(.+?)=([\s\S]*)$/);
if (!match) { if (!match) {
console.error('bad argument: ' + arg); console.error(`bad argument: ${arg}`);
process.exit(1); process.exit(1);
} }
const config = match[1]; const config = match[1];
@ -206,7 +206,7 @@ function formatResult(data) {
// Construct configuration string, " A=a, B=b, ..." // Construct configuration string, " A=a, B=b, ..."
let conf = ''; let conf = '';
for (const key of Object.keys(data.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('.'); var rate = data.rate.toString().split('.');

6
benchmark/compare.js

@ -79,14 +79,14 @@ if (showProgress) {
// Construct configuration string, " A=a, B=b, ..." // Construct configuration string, " A=a, B=b, ..."
let conf = ''; let conf = '';
for (const key of Object.keys(data.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); conf = conf.slice(1);
// Escape quotes (") for correct csv formatting // Escape quotes (") for correct csv formatting
conf = conf.replace(/"/g, '""'); conf = conf.replace(/"/g, '""');
console.log(`"${job.binary}", "${job.filename}", "${conf}", ` + console.log(`"${job.binary}", "${job.filename}", "${conf}", ${
`${data.rate}, ${data.time}`); data.rate}, ${data.time}`);
if (showProgress) { if (showProgress) {
// One item in the subqueue has been completed. // One item in the subqueue has been completed.
progress.completeConfig(data); progress.completeConfig(data);

2
benchmark/crypto/cipher-stream.js

@ -51,7 +51,7 @@ function main(conf) {
message = Buffer.alloc(conf.len, 'b'); message = Buffer.alloc(conf.len, 'b');
break; break;
default: default:
throw new Error('unknown message type: ' + conf.type); throw new Error(`unknown message type: ${conf.type}`);
} }
var fn = api === 'stream' ? streamWrite : legacyWrite; var fn = api === 'stream' ? streamWrite : legacyWrite;

2
benchmark/crypto/hash-stream-creation.js

@ -36,7 +36,7 @@ function main(conf) {
message = Buffer.alloc(conf.len, 'b'); message = Buffer.alloc(conf.len, 'b');
break; break;
default: default:
throw new Error('unknown message type: ' + conf.type); throw new Error(`unknown message type: ${conf.type}`);
} }
var fn = api === 'stream' ? streamWrite : legacyWrite; var fn = api === 'stream' ? streamWrite : legacyWrite;

2
benchmark/crypto/hash-stream-throughput.js

@ -35,7 +35,7 @@ function main(conf) {
message = Buffer.alloc(conf.len, 'b'); message = Buffer.alloc(conf.len, 'b');
break; break;
default: default:
throw new Error('unknown message type: ' + conf.type); throw new Error(`unknown message type: ${conf.type}`);
} }
var fn = api === 'stream' ? streamWrite : legacyWrite; var fn = api === 'stream' ? streamWrite : legacyWrite;

8
benchmark/crypto/rsa-encrypt-decrypt-throughput.js

@ -10,10 +10,10 @@ var RSA_PublicPem = {};
var RSA_PrivatePem = {}; var RSA_PrivatePem = {};
keylen_list.forEach(function(key) { keylen_list.forEach(function(key) {
RSA_PublicPem[key] = fs.readFileSync(fixtures_keydir + RSA_PublicPem[key] =
'/rsa_public_' + key + '.pem'); fs.readFileSync(`${fixtures_keydir}/rsa_public_${key}.pem`);
RSA_PrivatePem[key] = fs.readFileSync(fixtures_keydir + RSA_PrivatePem[key] =
'/rsa_private_' + key + '.pem'); fs.readFileSync(`${fixtures_keydir}/rsa_private_${key}.pem`);
}); });
var bench = common.createBenchmark(main, { var bench = common.createBenchmark(main, {

8
benchmark/crypto/rsa-sign-verify-throughput.js

@ -10,10 +10,10 @@ var RSA_PublicPem = {};
var RSA_PrivatePem = {}; var RSA_PrivatePem = {};
keylen_list.forEach(function(key) { keylen_list.forEach(function(key) {
RSA_PublicPem[key] = fs.readFileSync(fixtures_keydir + RSA_PublicPem[key] =
'/rsa_public_' + key + '.pem'); fs.readFileSync(`${fixtures_keydir}/rsa_public_${key}.pem`);
RSA_PrivatePem[key] = fs.readFileSync(fixtures_keydir + RSA_PrivatePem[key] =
'/rsa_private_' + key + '.pem'); fs.readFileSync(`${fixtures_keydir}/rsa_private_${key}.pem`);
}); });
var bench = common.createBenchmark(main, { var bench = common.createBenchmark(main, {

66
benchmark/es/map-bench.js

@ -16,11 +16,11 @@ function runObject(n) {
var i = 0; var i = 0;
bench.start(); bench.start();
for (; i < n; i++) { for (; i < n; i++) {
m['i' + i] = i; m[`i${i}`] = i;
m['s' + i] = String(i); m[`s${i}`] = String(i);
assert.strictEqual(String(m['i' + i]), m['s' + i]); assert.strictEqual(String(m[`i${i}`]), m[`s${i}`]);
m['i' + i] = undefined; m[`i${i}`] = undefined;
m['s' + i] = undefined; m[`s${i}`] = undefined;
} }
bench.end(n / 1e6); bench.end(n / 1e6);
} }
@ -30,11 +30,11 @@ function runNullProtoObject(n) {
var i = 0; var i = 0;
bench.start(); bench.start();
for (; i < n; i++) { for (; i < n; i++) {
m['i' + i] = i; m[`i${i}`] = i;
m['s' + i] = String(i); m[`s${i}`] = String(i);
assert.strictEqual(String(m['i' + i]), m['s' + i]); assert.strictEqual(String(m[`i${i}`]), m[`s${i}`]);
m['i' + i] = undefined; m[`i${i}`] = undefined;
m['s' + i] = undefined; m[`s${i}`] = undefined;
} }
bench.end(n / 1e6); bench.end(n / 1e6);
} }
@ -44,11 +44,11 @@ function runNullProtoLiteralObject(n) {
var i = 0; var i = 0;
bench.start(); bench.start();
for (; i < n; i++) { for (; i < n; i++) {
m['i' + i] = i; m[`i${i}`] = i;
m['s' + i] = String(i); m[`s${i}`] = String(i);
assert.strictEqual(String(m['i' + i]), m['s' + i]); assert.strictEqual(String(m[`i${i}`]), m[`s${i}`]);
m['i' + i] = undefined; m[`i${i}`] = undefined;
m['s' + i] = undefined; m[`s${i}`] = undefined;
} }
bench.end(n / 1e6); bench.end(n / 1e6);
} }
@ -61,11 +61,11 @@ function runStorageObject(n) {
var i = 0; var i = 0;
bench.start(); bench.start();
for (; i < n; i++) { for (; i < n; i++) {
m['i' + i] = i; m[`i${i}`] = i;
m['s' + i] = String(i); m[`s${i}`] = String(i);
assert.strictEqual(String(m['i' + i]), m['s' + i]); assert.strictEqual(String(m[`i${i}`]), m[`s${i}`]);
m['i' + i] = undefined; m[`i${i}`] = undefined;
m['s' + i] = undefined; m[`s${i}`] = undefined;
} }
bench.end(n / 1e6); bench.end(n / 1e6);
} }
@ -73,10 +73,10 @@ function runStorageObject(n) {
function fakeMap() { function fakeMap() {
const m = {}; const m = {};
return { return {
get(key) { return m['$' + key]; }, get(key) { return m[`$${key}`]; },
set(key, val) { m['$' + key] = val; }, set(key, val) { m[`$${key}`] = val; },
get size() { return Object.keys(m).length; }, 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; var i = 0;
bench.start(); bench.start();
for (; i < n; i++) { for (; i < n; i++) {
m.set('i' + i, i); m.set(`i${i}`, i);
m.set('s' + i, String(i)); m.set(`s${i}`, String(i));
assert.strictEqual(String(m.get('i' + i)), m.get('s' + i)); assert.strictEqual(String(m.get(`i${i}`)), m.get(`s${i}`));
m.set('i' + i, undefined); m.set(`i${i}`, undefined);
m.set('s' + i, undefined); m.set(`s${i}`, undefined);
} }
bench.end(n / 1e6); bench.end(n / 1e6);
} }
@ -99,11 +99,11 @@ function runMap(n) {
var i = 0; var i = 0;
bench.start(); bench.start();
for (; i < n; i++) { for (; i < n; i++) {
m.set('i' + i, i); m.set(`i${i}`, i);
m.set('s' + i, String(i)); m.set(`s${i}`, String(i));
assert.strictEqual(String(m.get('i' + i)), m.get('s' + i)); assert.strictEqual(String(m.get(`i${i}`)), m.get(`s${i}`));
m.set('i' + i, undefined); m.set(`i${i}`, undefined);
m.set('s' + i, undefined); m.set(`s${i}`, undefined);
} }
bench.end(n / 1e6); bench.end(n / 1e6);
} }

2
benchmark/fs/bench-realpath.js

@ -22,7 +22,7 @@ function main(conf) {
else if (type === 'resolved') else if (type === 'resolved')
resolvedPath(n); resolvedPath(n);
else else
throw new Error('unknown "type": ' + type); throw new Error(`unknown "type": ${type}`);
} }
function relativePath(n) { function relativePath(n) {

2
benchmark/fs/bench-realpathSync.js

@ -24,7 +24,7 @@ function main(conf) {
else if (type === 'resolved') else if (type === 'resolved')
resolvedPath(n); resolvedPath(n);
else else
throw new Error('unknown "type": ' + type); throw new Error(`unknown "type": ${type}`);
bench.end(n); bench.end(n);
} }

2
benchmark/http/_chunky_http_client.js

@ -37,7 +37,7 @@ function main(conf) {
for (var i = 0; i < extra_header_count; i++) { for (var i = 0; i < extra_header_count; i++) {
// Utilize first three powers of a small integer for an odd cycle and // Utilize first three powers of a small integer for an odd cycle and
// because the fourth power of some integers overloads the server. // 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('');
todo.push(''); todo.push('');

2
benchmark/http/cluster.js

@ -27,7 +27,7 @@ function main(conf) {
return; return;
setTimeout(function() { setTimeout(function() {
var path = '/' + conf.type + '/' + conf.len; var path = `/${conf.type}/${conf.len}`;
bench.http({ bench.http({
path: path, path: path,

4
benchmark/http/http_server_for_chunky_client.js

@ -6,7 +6,7 @@ var fs = require('fs');
var fork = require('child_process').fork; var fork = require('child_process').fork;
var common = require('../common.js'); var common = require('../common.js');
var test = require('../../test/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; var PIPE = test.PIPE;
try { try {
@ -30,7 +30,7 @@ server = http.createServer(function(req, res) {
}); });
server.on('error', function(err) { server.on('error', function(err) {
throw new Error('server error: ' + err); throw new Error(`server error: ${err}`);
}); });
server.listen(PIPE); server.listen(PIPE);

3
benchmark/http/simple.js

@ -16,8 +16,7 @@ function main(conf) {
var server = require('../fixtures/simple-http-server.js') var server = require('../fixtures/simple-http-server.js')
.listen(process.env.PORT || common.PORT) .listen(process.env.PORT || common.PORT)
.on('listening', function() { .on('listening', function() {
var path = '/' + conf.type + '/' + conf.len + '/' + conf.chunks + '/' + var path = `/${conf.type}/${conf.len}/${conf.chunks}/${conf.res}`;
conf.res;
bench.http({ bench.http({
path: path, path: path,

8
benchmark/misc/console.js

@ -21,7 +21,7 @@ var bench = common.createBenchmark(main, {
const nullStream = createNullStream(); const nullStream = createNullStream();
function usingRestAndConcat(...args) { 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) { function usingRestAndSpreadTS(...args) {
@ -37,15 +37,15 @@ function usingArgumentsAndApplyTS() {
} }
function usingRestAndSpreadC(...args) { function usingRestAndSpreadC(...args) {
nullStream.write(util.format(...args) + '\n'); nullStream.write(`${util.format(...args)}\n`);
} }
function usingRestAndApplyC(...args) { function usingRestAndApplyC(...args) {
nullStream.write(util.format.apply(null, args) + '\n'); nullStream.write(`${util.format.apply(null, args)}\n`);
} }
function usingArgumentsAndApplyC() { function usingArgumentsAndApplyC() {
nullStream.write(util.format.apply(null, arguments) + '\n'); nullStream.write(`${util.format.apply(null, arguments)}\n`);
} }
function runUsingRestAndConcat(n) { function runUsingRestAndConcat(n) {

8
benchmark/misc/v8-bench.js

@ -9,8 +9,8 @@ var dir = path.join(__dirname, '..', '..', 'deps', 'v8', 'benchmarks');
function load(filename, inGlobal) { function load(filename, inGlobal) {
var source = fs.readFileSync(path.join(dir, filename), 'utf8'); var source = fs.readFileSync(path.join(dir, filename), 'utf8');
if (!inGlobal) source = '(function () {' + source + '\n})()'; if (!inGlobal) source = `(function () {${source}\n})()`;
vm.runInThisContext(source, { filename: 'v8/bechmark/' + filename }); vm.runInThisContext(source, { filename: `v8/bechmark/${filename}` });
} }
load('base.js', true); load('base.js', true);
@ -41,13 +41,13 @@ global.BenchmarkSuite.RunSuites({
}); });
}, },
NotifyError: function(name, error) { NotifyError: function(name, error) {
console.error(name + ': ' + error); console.error(`${name}: ${error}`);
}, },
NotifyScore: function(score) { NotifyScore: function(score) {
common.sendResult({ common.sendResult({
name: benchmark_name, name: benchmark_name,
conf: { conf: {
benchmark: 'Score (version ' + global.BenchmarkSuite.version + ')' benchmark: `Score (version ${global.BenchmarkSuite.version})`
}, },
rate: score, rate: score,
time: 0 time: 0

14
benchmark/module/module-loader.js

@ -20,13 +20,13 @@ function main(conf) {
try { fs.mkdirSync(benchmarkDirectory); } catch (e) {} try { fs.mkdirSync(benchmarkDirectory); } catch (e) {}
for (var i = 0; i <= n; i++) { for (var i = 0; i <= n; i++) {
fs.mkdirSync(benchmarkDirectory + i); fs.mkdirSync(`${benchmarkDirectory}${i}`);
fs.writeFileSync( fs.writeFileSync(
benchmarkDirectory + i + '/package.json', `${benchmarkDirectory}${i}/package.json`,
'{"main": "index.js"}' '{"main": "index.js"}'
); );
fs.writeFileSync( fs.writeFileSync(
benchmarkDirectory + i + '/index.js', `${benchmarkDirectory}${i}/index.js`,
'module.exports = "";' 'module.exports = "";'
); );
} }
@ -43,12 +43,12 @@ function measureFull(n, useCache) {
var i; var i;
if (useCache) { if (useCache) {
for (i = 0; i <= n; i++) { for (i = 0; i <= n; i++) {
require(benchmarkDirectory + i + '/index.js'); require(`${benchmarkDirectory}${i}/index.js`);
} }
} }
bench.start(); bench.start();
for (i = 0; i <= n; i++) { for (i = 0; i <= n; i++) {
require(benchmarkDirectory + i + '/index.js'); require(`${benchmarkDirectory}${i}/index.js`);
} }
bench.end(n / 1e3); bench.end(n / 1e3);
} }
@ -57,12 +57,12 @@ function measureDir(n, useCache) {
var i; var i;
if (useCache) { if (useCache) {
for (i = 0; i <= n; i++) { for (i = 0; i <= n; i++) {
require(benchmarkDirectory + i); require(`${benchmarkDirectory}${i}`);
} }
} }
bench.start(); bench.start();
for (i = 0; i <= n; i++) { for (i = 0; i <= n; i++) {
require(benchmarkDirectory + i); require(`${benchmarkDirectory}${i}`);
} }
bench.end(n / 1e3); bench.end(n / 1e3);
} }

2
benchmark/net/net-c2s-cork.js

@ -34,7 +34,7 @@ function main(conf) {
chunk = 'x'.repeat(len); chunk = 'x'.repeat(len);
break; break;
default: default:
throw new Error('invalid type: ' + type); throw new Error(`invalid type: ${type}`);
} }
server(); server();

2
benchmark/net/net-c2s.js

@ -34,7 +34,7 @@ function main(conf) {
chunk = 'x'.repeat(len); chunk = 'x'.repeat(len);
break; break;
default: default:
throw new Error('invalid type: ' + type); throw new Error(`invalid type: ${type}`);
} }
server(); server();

2
benchmark/net/net-pipe.js

@ -34,7 +34,7 @@ function main(conf) {
chunk = 'x'.repeat(len); chunk = 'x'.repeat(len);
break; break;
default: default:
throw new Error('invalid type: ' + type); throw new Error(`invalid type: ${type}`);
} }
server(); server();

2
benchmark/net/net-s2c.js

@ -34,7 +34,7 @@ function main(conf) {
chunk = 'x'.repeat(len); chunk = 'x'.repeat(len);
break; break;
default: default:
throw new Error('invalid type: ' + type); throw new Error(`invalid type: ${type}`);
} }
server(); server();

2
benchmark/net/tcp-raw-c2s.js

@ -89,7 +89,7 @@ function client() {
chunk = 'x'.repeat(len); chunk = 'x'.repeat(len);
break; break;
default: default:
throw new Error('invalid type: ' + type); throw new Error(`invalid type: ${type}`);
} }
var clientHandle = new TCP(); var clientHandle = new TCP();

2
benchmark/net/tcp-raw-pipe.js

@ -86,7 +86,7 @@ function client() {
chunk = 'x'.repeat(len); chunk = 'x'.repeat(len);
break; break;
default: default:
throw new Error('invalid type: ' + type); throw new Error(`invalid type: ${type}`);
} }
var clientHandle = new TCP(); var clientHandle = new TCP();

2
benchmark/net/tcp-raw-s2c.js

@ -60,7 +60,7 @@ function server() {
chunk = 'x'.repeat(len); chunk = 'x'.repeat(len);
break; break;
default: default:
throw new Error('invalid type: ' + type); throw new Error(`invalid type: ${type}`);
} }
clientHandle.readStart(); clientHandle.readStart();

2
benchmark/path/basename-posix.js

@ -21,7 +21,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.posix; var p = path.posix;
var input = '' + conf.pathext; var input = String(conf.pathext);
var ext; var ext;
var extIdx = input.indexOf('|'); var extIdx = input.indexOf('|');
if (extIdx !== -1) { if (extIdx !== -1) {

2
benchmark/path/basename-win32.js

@ -21,7 +21,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.win32; var p = path.win32;
var input = '' + conf.pathext; var input = String(conf.pathext);
var ext; var ext;
var extIdx = input.indexOf('|'); var extIdx = input.indexOf('|');
if (extIdx !== -1) { if (extIdx !== -1) {

2
benchmark/path/dirname-posix.js

@ -18,7 +18,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.posix; var p = path.posix;
var input = '' + conf.path; var input = String(conf.path);
bench.start(); bench.start();
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {

2
benchmark/path/dirname-win32.js

@ -18,7 +18,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.win32; var p = path.win32;
var input = '' + conf.path; var input = String(conf.path);
bench.start(); bench.start();
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {

2
benchmark/path/extname-posix.js

@ -21,7 +21,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.posix; var p = path.posix;
var input = '' + conf.path; var input = String(conf.path);
bench.start(); bench.start();
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {

2
benchmark/path/extname-win32.js

@ -21,7 +21,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.win32; var p = path.win32;
var input = '' + conf.path; var input = String(conf.path);
bench.start(); bench.start();
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {

2
benchmark/path/format-posix.js

@ -12,7 +12,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.posix; var p = path.posix;
var props = ('' + conf.props).split('|'); var props = String(conf.props).split('|');
var obj = { var obj = {
root: props[0] || '', root: props[0] || '',
dir: props[1] || '', dir: props[1] || '',

2
benchmark/path/format-win32.js

@ -12,7 +12,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.win32; var p = path.win32;
var props = ('' + conf.props).split('|'); var props = String(conf.props).split('|');
var obj = { var obj = {
root: props[0] || '', root: props[0] || '',
dir: props[1] || '', dir: props[1] || '',

2
benchmark/path/isAbsolute-posix.js

@ -16,7 +16,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.posix; var p = path.posix;
var input = '' + conf.path; var input = String(conf.path);
bench.start(); bench.start();
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {

2
benchmark/path/isAbsolute-win32.js

@ -17,7 +17,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.win32; var p = path.win32;
var input = '' + conf.path; var input = String(conf.path);
bench.start(); bench.start();
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {

2
benchmark/path/join-posix.js

@ -12,7 +12,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.posix; var p = path.posix;
var args = ('' + conf.paths).split('|'); var args = String(conf.paths).split('|');
bench.start(); bench.start();
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {

2
benchmark/path/join-win32.js

@ -12,7 +12,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.win32; var p = path.win32;
var args = ('' + conf.paths).split('|'); var args = String(conf.paths).split('|');
bench.start(); bench.start();
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {

2
benchmark/path/makeLong-win32.js

@ -15,7 +15,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.win32; var p = path.win32;
var input = '' + conf.path; var input = String(conf.path);
bench.start(); bench.start();
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {

2
benchmark/path/normalize-posix.js

@ -17,7 +17,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.posix; var p = path.posix;
var input = '' + conf.path; var input = String(conf.path);
bench.start(); bench.start();
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {

2
benchmark/path/normalize-win32.js

@ -17,7 +17,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.win32; var p = path.win32;
var input = '' + conf.path; var input = String(conf.path);
bench.start(); bench.start();
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {

2
benchmark/path/parse-posix.js

@ -18,7 +18,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.posix; var p = path.posix;
var input = '' + conf.path; var input = String(conf.path);
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {
p.parse(input); p.parse(input);

2
benchmark/path/parse-win32.js

@ -19,7 +19,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.win32; var p = path.win32;
var input = '' + conf.path; var input = String(conf.path);
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {
p.parse(input); p.parse(input);

2
benchmark/path/relative-posix.js

@ -18,7 +18,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.posix; var p = path.posix;
var from = '' + conf.paths; var from = String(conf.paths);
var to = ''; var to = '';
var delimIdx = from.indexOf('|'); var delimIdx = from.indexOf('|');
if (delimIdx > -1) { if (delimIdx > -1) {

2
benchmark/path/relative-win32.js

@ -16,7 +16,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.win32; var p = path.win32;
var from = '' + conf.paths; var from = String(conf.paths);
var to = ''; var to = '';
var delimIdx = from.indexOf('|'); var delimIdx = from.indexOf('|');
if (delimIdx > -1) { if (delimIdx > -1) {

2
benchmark/path/resolve-posix.js

@ -15,7 +15,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.posix; var p = path.posix;
var args = ('' + conf.paths).split('|'); var args = String(conf.paths).split('|');
bench.start(); bench.start();
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {

2
benchmark/path/resolve-win32.js

@ -15,7 +15,7 @@ var bench = common.createBenchmark(main, {
function main(conf) { function main(conf) {
var n = +conf.n; var n = +conf.n;
var p = path.win32; var p = path.win32;
var args = ('' + conf.paths).split('|'); var args = String(conf.paths).split('|');
bench.start(); bench.start();
for (var i = 0; i < n; i++) { for (var i = 0; i < n; i++) {

2
benchmark/run.js

@ -50,7 +50,7 @@ if (format === 'csv') {
// Construct configuration string, " A=a, B=b, ..." // Construct configuration string, " A=a, B=b, ..."
let conf = ''; let conf = '';
for (const key of Object.keys(data.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 // delete first space of the configuration
conf = conf.slice(1); conf = conf.slice(1);

2
benchmark/scatter.js

@ -34,7 +34,7 @@ function csvEncodeValue(value) {
if (typeof value === 'number') { if (typeof value === 'number') {
return value.toString(); return value.toString();
} else { } else {
return '"' + value.replace(/"/g, '""') + '"'; return `"${value.replace(/"/g, '""')}"`;
} }
} }

2
benchmark/timers/timers-cancel-unpooled.js

@ -22,5 +22,5 @@ function main(conf) {
} }
function cb() { function cb() {
assert(false, 'Timer ' + this._idleTimeout + ' should not call callback'); assert(false, `Timer ${this._idleTimeout} should not call callback`);
} }

2
benchmark/timers/timers-insert-unpooled.js

@ -23,5 +23,5 @@ function main(conf) {
} }
function cb() { function cb() {
assert(false, 'Timer ' + this._idleTimeout + ' should not call callback'); assert(false, `Timer ${this._idleTimeout} should not call callback`);
} }

6
benchmark/tls/throughput.js

@ -38,9 +38,9 @@ function main(conf) {
} }
options = { options = {
key: fs.readFileSync(cert_dir + '/test_key.pem'), key: fs.readFileSync(`${cert_dir}/test_key.pem`),
cert: fs.readFileSync(cert_dir + '/test_cert.pem'), cert: fs.readFileSync(`${cert_dir}/test_cert.pem`),
ca: [ fs.readFileSync(cert_dir + '/test_ca.pem') ], ca: [ fs.readFileSync(`${cert_dir}/test_ca.pem`) ],
ciphers: 'AES256-GCM-SHA384' ciphers: 'AES256-GCM-SHA384'
}; };

6
benchmark/tls/tls-connect.js

@ -22,9 +22,9 @@ function main(conf) {
var cert_dir = path.resolve(__dirname, '../../test/fixtures'); var cert_dir = path.resolve(__dirname, '../../test/fixtures');
var options = { var options = {
key: fs.readFileSync(cert_dir + '/test_key.pem'), key: fs.readFileSync(`${cert_dir}/test_key.pem`),
cert: fs.readFileSync(cert_dir + '/test_cert.pem'), cert: fs.readFileSync(`${cert_dir}/test_cert.pem`),
ca: [ fs.readFileSync(cert_dir + '/test_ca.pem') ], ca: [ fs.readFileSync(`${cert_dir}/test_ca.pem`) ],
ciphers: 'AES256-GCM-SHA384' ciphers: 'AES256-GCM-SHA384'
}; };

4
benchmark/url/legacy-vs-whatwg-url-get-prop.js

@ -48,7 +48,7 @@ function useWHATWG(n, input) {
var obj = new URL(input); var obj = new URL(input);
var noDead = { var noDead = {
protocol: obj.protocol, protocol: obj.protocol,
auth: obj.username + ':' + obj.password, auth: `${obj.username}:${obj.password}`,
host: obj.host, host: obj.host,
hostname: obj.hostname, hostname: obj.hostname,
port: obj.port, port: obj.port,
@ -59,7 +59,7 @@ function useWHATWG(n, input) {
bench.start(); bench.start();
for (var i = 0; i < n; i += 1) { for (var i = 0; i < n; i += 1) {
noDead.protocol = obj.protocol; noDead.protocol = obj.protocol;
noDead.auth = obj.username + ':' + obj.password; noDead.auth = `${obj.username}:${obj.password}`;
noDead.host = obj.host; noDead.host = obj.host;
noDead.hostname = obj.hostname; noDead.hostname = obj.hostname;
noDead.port = obj.port; noDead.port = obj.port;

Loading…
Cancel
Save