diff --git a/Makefile b/Makefile index d638304c7a2784..e526ad5242d519 100644 --- a/Makefile +++ b/Makefile @@ -513,8 +513,8 @@ bench-idle: $(NODE) benchmark/idle_clients.js & jslint: - $(NODE) tools/eslint/bin/eslint.js lib src test tools/doc tools/eslint-rules \ - --rulesdir tools/eslint-rules + $(NODE) tools/eslint/bin/eslint.js benchmark lib src test tools/doc \ + tools/eslint-rules --rulesdir tools/eslint-rules CPPLINT_EXCLUDE ?= CPPLINT_EXCLUDE += src/node_lttng.cc diff --git a/benchmark/arrays/var-int.js b/benchmark/arrays/var-int.js index 47a7e62dc7681b..74a73c9515fffa 100644 --- a/benchmark/arrays/var-int.js +++ b/benchmark/arrays/var-int.js @@ -1,6 +1,9 @@ +'use strict'; var common = require('../common.js'); var bench = common.createBenchmark(main, { - type: 'Array Buffer Int8Array Uint8Array Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split(' '), + type: ['Array', 'Buffer', 'Int8Array', 'Uint8Array', 'Int16Array', + 'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array', + 'Float64Array'], n: [25] }); diff --git a/benchmark/arrays/zero-float.js b/benchmark/arrays/zero-float.js index a6624205bffdea..e2569eed5c4e75 100644 --- a/benchmark/arrays/zero-float.js +++ b/benchmark/arrays/zero-float.js @@ -1,6 +1,9 @@ +'use strict'; var common = require('../common.js'); var bench = common.createBenchmark(main, { - type: 'Array Buffer Int8Array Uint8Array Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split(' '), + type: ['Array', 'Buffer', 'Int8Array', 'Uint8Array', 'Int16Array', + 'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array', + 'Float64Array'], n: [25] }); diff --git a/benchmark/arrays/zero-int.js b/benchmark/arrays/zero-int.js index 29a2d58b665cbe..8be70c1e87113a 100644 --- a/benchmark/arrays/zero-int.js +++ b/benchmark/arrays/zero-int.js @@ -1,6 +1,9 @@ +'use strict'; var common = require('../common.js'); var bench = common.createBenchmark(main, { - type: 'Array Buffer Int8Array Uint8Array Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split(' '), + type: ['Array', 'Buffer', 'Int8Array', 'Uint8Array', 'Int16Array', + 'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array', + 'Float64Array'], n: [25] }); diff --git a/benchmark/buffers/buffer-base64-decode.js b/benchmark/buffers/buffer-base64-decode.js index 23ab92462f8927..36094f632d4eec 100644 --- a/benchmark/buffers/buffer-base64-decode.js +++ b/benchmark/buffers/buffer-base64-decode.js @@ -1,3 +1,4 @@ +'use strict'; const assert = require('assert'); const common = require('../common.js'); diff --git a/benchmark/buffers/buffer-base64-encode.js b/benchmark/buffers/buffer-base64-encode.js index cb520be2a621eb..8e2eec3cf5bb37 100644 --- a/benchmark/buffers/buffer-base64-encode.js +++ b/benchmark/buffers/buffer-base64-encode.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var bench = common.createBenchmark(main, {}); @@ -6,9 +7,10 @@ function main(conf) { var N = 64 * 1024 * 1024; var b = Buffer(N); var s = ''; - for (var i = 0; i < 256; ++i) s += String.fromCharCode(i); - for (var i = 0; i < N; i += 256) b.write(s, i, 256, 'ascii'); + var i; + for (i = 0; i < 256; ++i) s += String.fromCharCode(i); + for (i = 0; i < N; i += 256) b.write(s, i, 256, 'ascii'); bench.start(); - for (var i = 0; i < 32; ++i) b.toString('base64'); + for (i = 0; i < 32; ++i) b.toString('base64'); bench.end(64); } diff --git a/benchmark/buffers/buffer-bytelength.js b/benchmark/buffers/buffer-bytelength.js index 6a7afe6921aea1..50f420f412d30b 100644 --- a/benchmark/buffers/buffer-bytelength.js +++ b/benchmark/buffers/buffer-bytelength.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common'); var bench = common.createBenchmark(main, { @@ -43,7 +44,7 @@ function main(conf) { var r = Buffer.byteLength(strings[index], encoding); if (r !== results[index]) - throw Error('incorrect return value'); + throw new Error('incorrect return value'); } bench.end(n); } diff --git a/benchmark/buffers/buffer-compare.js b/benchmark/buffers/buffer-compare.js index b02e8a74030042..c83bb67fa24ad8 100644 --- a/benchmark/buffers/buffer-compare.js +++ b/benchmark/buffers/buffer-compare.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var bench = common.createBenchmark(main, { diff --git a/benchmark/buffers/buffer-creation.js b/benchmark/buffers/buffer-creation.js index bc0c55711858de..dfb68467cc54b9 100644 --- a/benchmark/buffers/buffer-creation.js +++ b/benchmark/buffers/buffer-creation.js @@ -1,4 +1,5 @@ -SlowBuffer = require('buffer').SlowBuffer; +'use strict'; +const SlowBuffer = require('buffer').SlowBuffer; var common = require('../common.js'); var bench = common.createBenchmark(main, { @@ -13,7 +14,7 @@ function main(conf) { var clazz = conf.type === 'fast' ? Buffer : SlowBuffer; bench.start(); for (var i = 0; i < n * 1024; i++) { - b = new clazz(len); + new clazz(len); } bench.end(n); } diff --git a/benchmark/buffers/buffer-indexof.js b/benchmark/buffers/buffer-indexof.js index c575f54b6a638c..6f10033020bc74 100644 --- a/benchmark/buffers/buffer-indexof.js +++ b/benchmark/buffers/buffer-indexof.js @@ -1,5 +1,7 @@ +'use strict'; var common = require('../common.js'); var fs = require('fs'); +const path = require('path'); var bench = common.createBenchmark(main, { search: ['@', 'SQ', '10x', '--l', 'Alice', 'Gryphon', 'Panther', @@ -14,7 +16,9 @@ var bench = common.createBenchmark(main, { function main(conf) { var iter = (conf.iter) * 100000; - var aliceBuffer = fs.readFileSync(__dirname + '/../fixtures/alice.html'); + var aliceBuffer = fs.readFileSync( + path.resolve(__dirname, '../fixtures/alice.html') + ); var search = conf.search; var encoding = conf.encoding; diff --git a/benchmark/buffers/buffer-iterate.js b/benchmark/buffers/buffer-iterate.js index 77a0b59b8ac081..fb8abc1aee1c63 100644 --- a/benchmark/buffers/buffer-iterate.js +++ b/benchmark/buffers/buffer-iterate.js @@ -1,3 +1,4 @@ +'use strict'; var SlowBuffer = require('buffer').SlowBuffer; var common = require('../common.js'); var assert = require('assert'); diff --git a/benchmark/buffers/buffer-read.js b/benchmark/buffers/buffer-read.js index 92138bccef99d6..2810aa1b463321 100644 --- a/benchmark/buffers/buffer-read.js +++ b/benchmark/buffers/buffer-read.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var bench = common.createBenchmark(main, { @@ -21,10 +22,10 @@ function main(conf) { 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")); + 'for (var i = 0; i !== ' + len + '; i++) {', + ' buff.' + fn + '(0, ' + JSON.stringify(noAssert) + ');', + '}' + ].join('\n')); bench.start(); testFunction(buff); bench.end(len / 1e6); diff --git a/benchmark/buffers/buffer-slice.js b/benchmark/buffers/buffer-slice.js index f632fa64adff11..70cf3a705c0d8b 100644 --- a/benchmark/buffers/buffer-slice.js +++ b/benchmark/buffers/buffer-slice.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var SlowBuffer = require('buffer').SlowBuffer; diff --git a/benchmark/buffers/buffer-tostring.js b/benchmark/buffers/buffer-tostring.js index 948052042d677b..f71c2b9a2b5127 100644 --- a/benchmark/buffers/buffer-tostring.js +++ b/benchmark/buffers/buffer-tostring.js @@ -14,12 +14,13 @@ function main(conf) { const n = conf.n | 0; const buf = Buffer(len).fill(42); + var i; bench.start(); if (arg) { - for (var i = 0; i < n; i += 1) + for (i = 0; i < n; i += 1) buf.toString('utf8'); } else { - for (var i = 0; i < n; i += 1) + for (i = 0; i < n; i += 1) buf.toString(); } bench.end(n); diff --git a/benchmark/buffers/buffer-write.js b/benchmark/buffers/buffer-write.js index 2a2a0e37e3adda..4e07fc511be12a 100644 --- a/benchmark/buffers/buffer-write.js +++ b/benchmark/buffers/buffer-write.js @@ -1,4 +1,4 @@ - +'use strict'; var common = require('../common.js'); var bench = common.createBenchmark(main, { noAssert: [false, true], @@ -48,10 +48,10 @@ 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")); + 'for (var i = 0; i !== ' + len + '; i++) {', + ' buff.' + fn + '(i & ' + m + ', 0, ' + JSON.stringify(noAssert) + ');', + '}' + ].join('\n')); bench.start(); testFunction(buff); bench.end(len / 1e6); @@ -59,10 +59,10 @@ function benchInt(buff, fn, len, noAssert) { 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")); + 'for (var i = 0; i !== ' + len + '; i++) {', + ' buff.' + fn + '(i, 0, ' + JSON.stringify(noAssert) + ');', + '}' + ].join('\n')); bench.start(); testFunction(buff); bench.end(len / 1e6); diff --git a/benchmark/buffers/dataview-set.js b/benchmark/buffers/dataview-set.js index ce0064edb6e0cd..ab9c1d1d23b736 100644 --- a/benchmark/buffers/dataview-set.js +++ b/benchmark/buffers/dataview-set.js @@ -1,4 +1,4 @@ - +'use strict'; var common = require('../common.js'); var bench = common.createBenchmark(main, { type: ['Uint8', 'Uint16LE', 'Uint16BE', diff --git a/benchmark/common.js b/benchmark/common.js index 511ae384f418bf..69c3d00ee2e1f1 100644 --- a/benchmark/common.js +++ b/benchmark/common.js @@ -1,3 +1,4 @@ +'use strict'; var assert = require('assert'); var fs = require('fs'); var path = require('path'); @@ -27,7 +28,7 @@ if (module === require.main) { var tests = fs.readdirSync(dir); if (testFilter) { - var filteredTests = tests.filter(function(item){ + var filteredTests = tests.filter(function(item) { if (item.lastIndexOf(testFilter) >= 0) { return item; } @@ -48,7 +49,7 @@ function hasWrk() { if (result.error && result.error.code === 'ENOENT') { console.error('Couldn\'t locate `wrk` which is needed for running ' + 'benchmarks. Check benchmark/README.md for further instructions.'); - process.exit(-1); + process.exit(-1); } } @@ -86,7 +87,7 @@ function Benchmark(fn, options) { this.options = options; this.config = parseOpts(options); this._name = require.main.filename.split(/benchmark[\/\\]/).pop(); - this._start = [0,0]; + this._start = [0, 0]; this._started = false; var self = this; @@ -120,7 +121,7 @@ Benchmark.prototype.http = function(p, args, cb) { if (code) { console.error('wrk failed with ' + code); - process.exit(code) + process.exit(code); } var match = out.match(regexp); var qps = match && +match[1]; @@ -140,8 +141,6 @@ Benchmark.prototype._run = function() { // some options weren't set. // run with all combinations var main = require.main.filename; - var settings = []; - var queueLen = 1; var options = this.options; var queue = Object.keys(options).reduce(function(set, key) { @@ -192,7 +191,7 @@ function parseOpts(options) { if (!match || !match[1] || !match[2] || !options[match[1]]) { return null; } else { - conf[match[1]] = isFinite(match[2]) ? +match[2] : match[2] + conf[match[1]] = isFinite(match[2]) ? +match[2] : match[2]; num--; } } @@ -203,7 +202,7 @@ function parseOpts(options) { }); } return num === 0 ? conf : null; -}; +} Benchmark.prototype.start = function() { if (this._started) @@ -221,8 +220,8 @@ Benchmark.prototype.end = function(operations) { if (typeof operations !== 'number') throw new Error('called end() without specifying operation count'); - var time = elapsed[0] + elapsed[1]/1e9; - var rate = operations/time; + var time = elapsed[0] + elapsed[1] / 1e9; + var rate = operations / time; this.report(rate); }; diff --git a/benchmark/compare.js b/benchmark/compare.js index edb116d0c64baa..44854aefa7b5e8 100644 --- a/benchmark/compare.js +++ b/benchmark/compare.js @@ -1,3 +1,4 @@ +'use strict'; var usage = 'node benchmark/compare.js ' + ' ' + '[--html] [--red|-r] [--green|-g] ' + @@ -36,18 +37,19 @@ for (var i = 2; i < process.argv.length; i++) { } } +var start, green, red, reset, end; if (!html) { - var start = ''; - var green = '\033[1;32m'; - var red = '\033[1;31m'; - var reset = '\033[m'; - var end = ''; + start = ''; + green = '\u001b[1;32m'; + red = '\u001b[1;31m'; + reset = '\u001b[m'; + end = ''; } else { - var start = '
';
-  var green = '';
-  var red = '';
-  var reset = '';
-  var end = '
'; + start = '
';
+  green = '';
+  red = '';
+  reset = '';
+  end = '
'; } var runBench = process.env.NODE_BENCH || 'bench'; @@ -75,10 +77,15 @@ function run() { var out = ''; var child; - if (Array.isArray(benchmarks) && benchmarks.length) - child = spawn(node, ['benchmark/common.js'].concat(benchmarks), { env: env }); - else + if (Array.isArray(benchmarks) && benchmarks.length) { + child = spawn( + node, + ['benchmark/common.js'].concat(benchmarks), + { env: env } + ); + } else { child = spawn('make', [runBench], { env: env }); + } child.stdout.setEncoding('utf8'); child.stdout.on('data', function(c) { out += c; @@ -134,9 +141,20 @@ function compare() { if (show === 'green' && !g || show === 'red' && !r) return; - var r0 = util.format('%s%s: %d%s', g, nodes[0], n0.toPrecision(5), g ? reset : ''); - var r1 = util.format('%s%s: %d%s', r, nodes[1], n1.toPrecision(5), r ? reset : ''); - var pct = c + pct + '%' + reset; + var r0 = util.format( + '%s%s: %d%s', + g, + nodes[0], + n0.toPrecision(5), g ? reset : '' + ); + var r1 = util.format( + '%s%s: %d%s', + r, + nodes[1], + n1.toPrecision(5), r ? reset : '' + ); + pct = c + pct + '%' + reset; + var l = util.format('%s: %s %s', bench, r0, r1); maxLen = Math.max(l.length + pct.length, maxLen); return [l, pct]; diff --git a/benchmark/crypto/aes-gcm-throughput.js b/benchmark/crypto/aes-gcm-throughput.js index 65e1713f0eb1c6..fc379b21b748bf 100644 --- a/benchmark/crypto/aes-gcm-throughput.js +++ b/benchmark/crypto/aes-gcm-throughput.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var crypto = require('crypto'); var keylen = {'aes-128-gcm': 16, 'aes-192-gcm': 24, 'aes-256-gcm': 32}; @@ -30,7 +31,7 @@ function AEAD_Bench(cipher, message, associate_data, key, iv, n, len) { var bob = crypto.createDecipheriv(cipher, key, iv); bob.setAuthTag(tag); bob.setAAD(associate_data); - var clear = bob.update(enc); + bob.update(enc); bob.final(); } diff --git a/benchmark/crypto/cipher-stream.js b/benchmark/crypto/cipher-stream.js index 4e8198931729f4..5da6f2481ecbc3 100644 --- a/benchmark/crypto/cipher-stream.js +++ b/benchmark/crypto/cipher-stream.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var bench = common.createBenchmark(main, { @@ -85,17 +86,17 @@ function streamWrite(alice, bob, message, encoding, writes) { function legacyWrite(alice, bob, message, encoding, writes) { var written = 0; + var enc, dec; for (var i = 0; i < writes; i++) { - var enc = alice.update(message, encoding); - var dec = bob.update(enc); + enc = alice.update(message, encoding); + dec = bob.update(enc); written += dec.length; } - var enc = alice.final(); - var dec = bob.update(enc); + enc = alice.final(); + dec = bob.update(enc); written += dec.length; dec = bob.final(); written += dec.length; - var bits = written * 8; var gbits = written / (1024 * 1024 * 1024); bench.end(gbits); } diff --git a/benchmark/crypto/hash-stream-creation.js b/benchmark/crypto/hash-stream-creation.js index a14aa220120e4e..4bcd37f00aaae8 100644 --- a/benchmark/crypto/hash-stream-creation.js +++ b/benchmark/crypto/hash-stream-creation.js @@ -1,5 +1,6 @@ // throughput benchmark // creates a single hasher, then pushes a bunch of data through it +'use strict'; var common = require('../common.js'); var crypto = require('crypto'); @@ -20,9 +21,6 @@ function main(conf) { api = 'legacy'; } - var crypto = require('crypto'); - var assert = require('assert'); - var message; var encoding; switch (conf.type) { diff --git a/benchmark/crypto/hash-stream-throughput.js b/benchmark/crypto/hash-stream-throughput.js index 2e987f03f5a1cf..050bbeb1ae54d3 100644 --- a/benchmark/crypto/hash-stream-throughput.js +++ b/benchmark/crypto/hash-stream-throughput.js @@ -1,5 +1,6 @@ // throughput benchmark // creates a single hasher, then pushes a bunch of data through it +'use strict'; var common = require('../common.js'); var crypto = require('crypto'); @@ -19,9 +20,6 @@ function main(conf) { api = 'legacy'; } - var crypto = require('crypto'); - var assert = require('assert'); - var message; var encoding; switch (conf.type) { diff --git a/benchmark/crypto/rsa-encrypt-decrypt-throughput.js b/benchmark/crypto/rsa-encrypt-decrypt-throughput.js index 1cd7a5e632910b..cf0579134cfb62 100644 --- a/benchmark/crypto/rsa-encrypt-decrypt-throughput.js +++ b/benchmark/crypto/rsa-encrypt-decrypt-throughput.js @@ -1,3 +1,4 @@ +'use strict'; // throughput benchmark in signing and verifying var common = require('../common.js'); var crypto = require('crypto'); @@ -22,7 +23,6 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var crypto = require('crypto'); var message = (new Buffer(conf.len)).fill('b'); bench.start(); @@ -38,7 +38,7 @@ function StreamWrite(algo, keylen, message, n, len) { var publicKey = RSA_PublicPem[keylen]; for (var i = 0; i < n; i++) { var enc = crypto.privateEncrypt(privateKey, message); - var clear = crypto.publicDecrypt(publicKey, enc); + crypto.publicDecrypt(publicKey, enc); } bench.end(kbits); diff --git a/benchmark/crypto/rsa-sign-verify-throughput.js b/benchmark/crypto/rsa-sign-verify-throughput.js index fd4260417b2221..779cc8bca1c6a8 100644 --- a/benchmark/crypto/rsa-sign-verify-throughput.js +++ b/benchmark/crypto/rsa-sign-verify-throughput.js @@ -1,3 +1,4 @@ +'use strict'; // throughput benchmark in signing and verifying var common = require('../common.js'); var crypto = require('crypto'); @@ -23,7 +24,6 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - var crypto = require('crypto'); var message = (new Buffer(conf.len)).fill('b'); bench.start(); @@ -36,7 +36,6 @@ function StreamWrite(algo, keylen, message, writes, len) { var kbits = bits / (1024); var privateKey = RSA_PrivatePem[keylen]; - var publicKey = RSA_PublicPem[keylen]; var s = crypto.createSign(algo); var v = crypto.createVerify(algo); @@ -45,7 +44,7 @@ function StreamWrite(algo, keylen, message, writes, len) { v.update(message); } - var sign = s.sign(privateKey, 'binary'); + s.sign(privateKey, 'binary'); s.end(); v.end(); diff --git a/benchmark/events/ee-add-remove.js b/benchmark/events/ee-add-remove.js index cd9fe3cb7de057..99d85367cb8d6f 100644 --- a/benchmark/events/ee-add-remove.js +++ b/benchmark/events/ee-add-remove.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var events = require('events'); @@ -9,14 +10,15 @@ function main(conf) { var ee = new events.EventEmitter(); var listeners = []; - for (var k = 0; k < 10; k += 1) + var k; + for (k = 0; k < 10; k += 1) listeners.push(function() {}); bench.start(); for (var i = 0; i < n; i += 1) { - for (var k = listeners.length; --k >= 0; /* empty */) + for (k = listeners.length; --k >= 0; /* empty */) ee.on('dummy', listeners[k]); - for (var k = listeners.length; --k >= 0; /* empty */) + for (k = listeners.length; --k >= 0; /* empty */) ee.removeListener('dummy', listeners[k]); } bench.end(n); diff --git a/benchmark/events/ee-emit-multi-args.js b/benchmark/events/ee-emit-multi-args.js index 78a892d457095d..b423c216b1ed73 100644 --- a/benchmark/events/ee-emit-multi-args.js +++ b/benchmark/events/ee-emit-multi-args.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var EventEmitter = require('events').EventEmitter; @@ -7,7 +8,6 @@ function main(conf) { var n = conf.n | 0; var ee = new EventEmitter(); - var listeners = []; for (var k = 0; k < 10; k += 1) ee.on('dummy', function() {}); diff --git a/benchmark/events/ee-emit.js b/benchmark/events/ee-emit.js index 4c45bd9b719665..87772222f0a467 100644 --- a/benchmark/events/ee-emit.js +++ b/benchmark/events/ee-emit.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var EventEmitter = require('events').EventEmitter; diff --git a/benchmark/events/ee-listener-count-on-prototype.js b/benchmark/events/ee-listener-count-on-prototype.js index 8d536edd62739b..dfe7e27cd09144 100644 --- a/benchmark/events/ee-listener-count-on-prototype.js +++ b/benchmark/events/ee-listener-count-on-prototype.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var EventEmitter = require('events').EventEmitter; @@ -13,7 +14,7 @@ function main(conf) { bench.start(); for (var i = 0; i < n; i += 1) { - var r = ee.listenerCount('dummy'); + ee.listenerCount('dummy'); } bench.end(n); } diff --git a/benchmark/events/ee-listeners-many.js b/benchmark/events/ee-listeners-many.js index 32721b32e56527..063732e1facb4b 100644 --- a/benchmark/events/ee-listeners-many.js +++ b/benchmark/events/ee-listeners-many.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var EventEmitter = require('events').EventEmitter; @@ -14,7 +15,7 @@ function main(conf) { bench.start(); for (var i = 0; i < n; i += 1) { - var r = ee.listeners('dummy'); + ee.listeners('dummy'); } bench.end(n); } diff --git a/benchmark/events/ee-listeners.js b/benchmark/events/ee-listeners.js index 68339bc3eca77a..e91ca5078f5f98 100644 --- a/benchmark/events/ee-listeners.js +++ b/benchmark/events/ee-listeners.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var EventEmitter = require('events').EventEmitter; @@ -13,7 +14,7 @@ function main(conf) { bench.start(); for (var i = 0; i < n; i += 1) { - var r = ee.listeners('dummy'); + ee.listeners('dummy'); } bench.end(n); } diff --git a/benchmark/fs-write-stream-throughput.js b/benchmark/fs-write-stream-throughput.js index b131d5b736fd38..4c767cf666e579 100644 --- a/benchmark/fs-write-stream-throughput.js +++ b/benchmark/fs-write-stream-throughput.js @@ -1,5 +1,5 @@ - // If there are no args, then this is the root. Run all the benchmarks! +'use strict'; if (!process.argv[2]) parent(); else @@ -39,24 +39,24 @@ function parent() { function runTest(dur, size, type) { if (type !== 'string') type = 'buffer'; + var chunk; switch (type) { case 'string': - var chunk = new Array(size + 1).join('a'); + chunk = new Array(size + 1).join('a'); break; case 'buffer': - var chunk = new Buffer(size); + chunk = new Buffer(size); chunk.fill('a'); break; } - var writes = 0; var fs = require('fs'); try { fs.unlinkSync('write_stream_throughput'); } catch (e) {} - var start + var start; var end; function done() { - var time = end[0] + end[1]/1E9; + var time = end[0] + end[1] / 1E9; var written = fs.statSync('write_stream_throughput').size / 1024; var rate = (written / time).toFixed(2); console.log('fs_write_stream_dur_%d_size_%d_type_%s: %d', diff --git a/benchmark/fs/read-stream-throughput.js b/benchmark/fs/read-stream-throughput.js index a181a2df60291c..c305485cd5f8dc 100644 --- a/benchmark/fs/read-stream-throughput.js +++ b/benchmark/fs/read-stream-throughput.js @@ -1,4 +1,5 @@ // test the throughput of the fs.WriteStream class. +'use strict'; var path = require('path'); var common = require('../common.js'); @@ -11,7 +12,7 @@ var type, encoding, size; var bench = common.createBenchmark(main, { type: ['buf', 'asc', 'utf'], - size: [1024, 4096, 65535, 1024*1024] + size: [1024, 4096, 65535, 1024 * 1024] }); function main(conf) { diff --git a/benchmark/fs/readfile.js b/benchmark/fs/readfile.js index ac3241901b931e..0f39f64f57c418 100644 --- a/benchmark/fs/readfile.js +++ b/benchmark/fs/readfile.js @@ -1,6 +1,7 @@ // Call fs.readFile over and over again really fast. // Then see how many times it got called. // Yes, this is a silly benchmark. Most benchmarks are silly. +'use strict'; var path = require('path'); var common = require('../common.js'); diff --git a/benchmark/fs/write-stream-throughput.js b/benchmark/fs/write-stream-throughput.js index 9ff58389c7959d..4f41d2b4bb4af3 100644 --- a/benchmark/fs/write-stream-throughput.js +++ b/benchmark/fs/write-stream-throughput.js @@ -1,4 +1,5 @@ // test the throughput of the fs.WriteStream class. +'use strict'; var path = require('path'); var common = require('../common.js'); @@ -28,7 +29,7 @@ function main(conf) { encoding = 'ascii'; break; case 'utf': - chunk = new Array(Math.ceil(size/2) + 1).join('ü'); + chunk = new Array(Math.ceil(size / 2) + 1).join('ü'); encoding = 'utf8'; break; default: diff --git a/benchmark/http/_chunky_http_client.js b/benchmark/http/_chunky_http_client.js index 24e14ca2bc9b0e..158be5a0eb6424 100644 --- a/benchmark/http/_chunky_http_client.js +++ b/benchmark/http/_chunky_http_client.js @@ -15,7 +15,6 @@ var bench = common.createBenchmark(main, { function main(conf) { var len = +conf.len; var num = +conf.num; - var type = conf.type; var todo = []; var headers = []; // Chose 7 because 9 showed "Connection error" / "Connection closed" @@ -24,7 +23,7 @@ function main(conf) { headers.push(Array(i + 1).join('o')); function WriteHTTPHeaders(channel, has_keep_alive, extra_header_count) { - todo = [] + todo = []; todo.push('GET / HTTP/1.1'); todo.push('Host: localhost'); todo.push('Connection: keep-alive'); @@ -63,7 +62,7 @@ function main(conf) { var socket = net.connect(PIPE, function() { bench.start(); WriteHTTPHeaders(socket, 1, len); - socket.setEncoding('utf8') + socket.setEncoding('utf8'); socket.on('data', function(d) { var did = false; var pattern = 'HTTP/1.1 200 OK\r\n'; @@ -73,7 +72,7 @@ function main(conf) { success += 1; did = true; } else { - pattern = 'HTTP/1.1 ' + pattern = 'HTTP/1.1 '; if ((d.length === pattern.length && d === pattern) || (d.length > pattern.length && d.slice(0, pattern.length) === pattern)) { diff --git a/benchmark/http/chunked.js b/benchmark/http/chunked.js index 0589ff3166f04d..642f2962cdce78 100644 --- a/benchmark/http/chunked.js +++ b/benchmark/http/chunked.js @@ -6,9 +6,9 @@ // always as hot as it could be. // // Verify that our assumptions are valid. +'use strict'; var common = require('../common.js'); -var PORT = common.PORT; var bench = common.createBenchmark(main, { num: [1, 4, 8, 16], @@ -17,7 +17,7 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - http = require('http'); + const http = require('http'); var chunk = new Buffer(conf.size); chunk.fill('8'); diff --git a/benchmark/http/client-request-body.js b/benchmark/http/client-request-body.js index 1c27dea2a2066e..befa3811ddd1c3 100644 --- a/benchmark/http/client-request-body.js +++ b/benchmark/http/client-request-body.js @@ -1,4 +1,5 @@ // Measure the time it takes for the HTTP client to send a request body. +'use strict'; var common = require('../common.js'); var http = require('http'); diff --git a/benchmark/http/cluster.js b/benchmark/http/cluster.js index 6391704ff7836b..9934883f7c3fa4 100644 --- a/benchmark/http/cluster.js +++ b/benchmark/http/cluster.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var PORT = common.PORT; diff --git a/benchmark/http/end-vs-write-end.js b/benchmark/http/end-vs-write-end.js index c17e2ffb45fa02..4e12e543f0bd92 100644 --- a/benchmark/http/end-vs-write-end.js +++ b/benchmark/http/end-vs-write-end.js @@ -6,9 +6,9 @@ // always as hot as it could be. // // Verify that our assumptions are valid. +'use strict'; var common = require('../common.js'); -var PORT = common.PORT; var bench = common.createBenchmark(main, { type: ['asc', 'utf', 'buf'], @@ -18,7 +18,7 @@ var bench = common.createBenchmark(main, { }); function main(conf) { - http = require('http'); + const http = require('http'); var chunk; var len = conf.kb * 1024; switch (conf.type) { @@ -27,7 +27,6 @@ function main(conf) { chunk.fill('x'); break; case 'utf': - encoding = 'utf8'; chunk = new Array(len / 2 + 1).join('ü'); break; case 'asc': diff --git a/benchmark/http/http_server_for_chunky_client.js b/benchmark/http/http_server_for_chunky_client.js index dede7daa7cdc75..d85e15bcbed4e9 100644 --- a/benchmark/http/http_server_for_chunky_client.js +++ b/benchmark/http/http_server_for_chunky_client.js @@ -4,8 +4,8 @@ var path = require('path'); var http = require('http'); var fs = require('fs'); var spawn = require('child_process').spawn; -var common = require('../common.js') -var test = require('../../test/common.js') +require('../common.js'); +var test = require('../../test/common.js'); var pep = path.dirname(process.argv[1]) + '/_chunky_http_client.js'; var PIPE = test.PIPE; @@ -38,17 +38,17 @@ try { child = spawn(process.execPath, [pep], { }); child.on('error', function(err) { - throw new Error('spawn error: ' + err ); + throw new Error('spawn error: ' + err); }); child.stdout.pipe(process.stdout); child.stderr.pipe(process.stderr); - child.on('close', function (exitCode) { + child.on('close', function(exitCode) { server.close(); }); -} catch(e) { - throw new Error('error: ' + e ); +} catch (e) { + throw new Error('error: ' + e); } diff --git a/benchmark/http/simple.js b/benchmark/http/simple.js index 5bff9283cb51a1..5449c49be97614 100644 --- a/benchmark/http/simple.js +++ b/benchmark/http/simple.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var PORT = common.PORT; @@ -11,7 +12,6 @@ var bench = common.createBenchmark(main, { function main(conf) { process.env.PORT = PORT; - var spawn = require('child_process').spawn; var server = require('../http_simple.js'); setTimeout(function() { var path = '/' + conf.type + '/' + conf.length + '/' + conf.chunks; diff --git a/benchmark/http_bench.js b/benchmark/http_bench.js index a8f99e2f0e7978..354993a2706a95 100644 --- a/benchmark/http_bench.js +++ b/benchmark/http_bench.js @@ -1,3 +1,4 @@ +'use strict'; var spawn = require('child_process').spawn; var cluster = require('cluster'); var http = require('http'); @@ -20,10 +21,10 @@ for (var i = 2; i < process.argv.length; ++i) { } switch (options.mode) { -case 'master': startMaster(); break; -case 'server': startServer(); break; -case 'client': startClient(); break; -default: throw new Error('Bad mode: ' + options.mode); + case 'master': startMaster(); break; + case 'server': startServer(); break; + case 'client': startClient(); break; + default: throw new Error('Bad mode: ' + options.mode); } process.title = 'http_bench[' + options.mode + ']'; @@ -47,7 +48,7 @@ function startMaster() { var forkCount = 0; - cluster.on('online', function () { + cluster.on('online', function() { forkCount = forkCount + 1; if (forkCount === ~~options.servers) { var args = [ diff --git a/benchmark/http_server_lag.js b/benchmark/http_server_lag.js index ca923d5b34afde..a3c18628ec68ba 100644 --- a/benchmark/http_server_lag.js +++ b/benchmark/http_server_lag.js @@ -1,3 +1,5 @@ +'use strict'; + var http = require('http'); var port = parseInt(process.env.PORT, 10) || 8000; var defaultLag = parseInt(process.argv[2], 10) || 100; @@ -6,7 +8,7 @@ http.createServer(function(req, res) { res.writeHead(200, { 'content-type': 'text/plain', 'content-length': '2' }); - var lag = parseInt(req.url.split("/").pop(), 10) || defaultLag; + var lag = parseInt(req.url.split('/').pop(), 10) || defaultLag; setTimeout(function() { res.end('ok'); }, lag); diff --git a/benchmark/http_simple.js b/benchmark/http_simple.js index 36800f2c9dba5a..0f36d3b6ce3ebd 100644 --- a/benchmark/http_simple.js +++ b/benchmark/http_simple.js @@ -1,13 +1,13 @@ -var path = require('path'), - exec = require('child_process').exec, - http = require('http'); +'use strict'; + +var http = require('http'); var port = parseInt(process.env.PORT || 8000); var fixed = makeString(20 * 1024, 'C'), - storedBytes = {}, - storedBuffer = {}, - storedUnicode = {}; + storedBytes = {}, + storedBuffer = {}, + storedUnicode = {}; var useDomains = process.env.NODE_USE_DOMAINS; @@ -22,7 +22,7 @@ if (useDomains) { gdom.enter(); } -var server = module.exports = http.createServer(function (req, res) { +var server = module.exports = http.createServer(function(req, res) { if (useDomains) { var dom = domain.create(); dom.add(req); @@ -36,29 +36,30 @@ var server = module.exports = http.createServer(function (req, res) { var n_chunks = parseInt(commands[3], 10); var status = 200; + var n, i; if (command == 'bytes') { - var n = ~~arg; + n = ~~arg; if (n <= 0) - throw new Error('bytes called with n <= 0') + throw new Error('bytes called with n <= 0'); if (storedBytes[n] === undefined) { storedBytes[n] = makeString(n, 'C'); } body = storedBytes[n]; } else if (command == 'buffer') { - var n = ~~arg; + n = ~~arg; if (n <= 0) throw new Error('buffer called with n <= 0'); if (storedBuffer[n] === undefined) { storedBuffer[n] = new Buffer(n); - for (var i = 0; i < n; i++) { + for (i = 0; i < n; i++) { storedBuffer[n][i] = 'C'.charCodeAt(0); } } body = storedBuffer[n]; } else if (command == 'unicode') { - var n = ~~arg; + n = ~~arg; if (n <= 0) throw new Error('unicode called with n <= 0'); if (storedUnicode[n] === undefined) { @@ -93,7 +94,7 @@ var server = module.exports = http.createServer(function (req, res) { var len = body.length; var step = Math.floor(len / n_chunks) || 1; - for (var i = 0, n = (n_chunks - 1); i < n; ++i) { + for (i = 0, n = (n_chunks - 1); i < n; ++i) { res.write(body.slice(i * step, i * step + step)); } res.end(body.slice((n_chunks - 1) * step)); @@ -114,7 +115,7 @@ function makeString(size, c) { return s; } -server.listen(port, function () { +server.listen(port, function() { if (module === require.main) - console.error('Listening at http://127.0.0.1:'+port+'/'); + console.error('Listening at http://127.0.0.1:' + port + '/'); }); diff --git a/benchmark/http_simple_auto.js b/benchmark/http_simple_auto.js index f72cc01e60aa46..6f56879cc08aaa 100644 --- a/benchmark/http_simple_auto.js +++ b/benchmark/http_simple_auto.js @@ -6,94 +6,95 @@ // Arguments to pass to `ab`. // Target to benchmark, e.g. `bytes/1024` or `buffer/8192`. // +'use strict'; -var path = require("path"); -var http = require("http"); -var spawn = require("child_process").spawn; +var http = require('http'); +var spawn = require('child_process').spawn; var port = parseInt(process.env.PORT || 8000); -var fixed = "" -for (var i = 0; i < 20*1024; i++) { - fixed += "C"; +var fixed = ''; +var i; +for (i = 0; i < 20 * 1024; i++) { + fixed += 'C'; } var stored = {}; var storedBuffer = {}; -var server = http.createServer(function (req, res) { - var commands = req.url.split("/"); +var server = http.createServer(function(req, res) { + var commands = req.url.split('/'); var command = commands[1]; - var body = ""; + var body = ''; var arg = commands[2]; var n_chunks = parseInt(commands[3], 10); var status = 200; + var n; - if (command == "bytes") { - var n = parseInt(arg, 10) + if (command == 'bytes') { + n = parseInt(arg, 10); if (n <= 0) - throw "bytes called with n <= 0" + throw new Error('bytes called with n <= 0'); if (stored[n] === undefined) { - stored[n] = ""; - for (var i = 0; i < n; i++) { - stored[n] += "C" + stored[n] = ''; + for (i = 0; i < n; i++) { + stored[n] += 'C'; } } body = stored[n]; - - } else if (command == "buffer") { - var n = parseInt(arg, 10) - if (n <= 0) throw new Error("bytes called with n <= 0"); + } else if (command == 'buffer') { + n = parseInt(arg, 10); + if (n <= 0) throw new Error('bytes called with n <= 0'); if (storedBuffer[n] === undefined) { storedBuffer[n] = new Buffer(n); - for (var i = 0; i < n; i++) { - storedBuffer[n][i] = "C".charCodeAt(0); + for (i = 0; i < n; i++) { + storedBuffer[n][i] = 'C'.charCodeAt(0); } } body = storedBuffer[n]; - } else if (command == "quit") { + } else if (command == 'quit') { res.connection.server.close(); - body = "quitting"; + body = 'quitting'; - } else if (command == "fixed") { + } else if (command == 'fixed') { body = fixed; - } else if (command == "echo") { - res.writeHead(200, { "Content-Type": "text/plain", - "Transfer-Encoding": "chunked" }); + } else if (command == 'echo') { + res.writeHead(200, { 'Content-Type': 'text/plain', + 'Transfer-Encoding': 'chunked' }); req.pipe(res); return; } else { status = 404; - body = "not found\n"; + body = 'not found\n'; } // example: http://localhost:port/bytes/512/4 // sends a 512 byte body in 4 chunks of 128 bytes if (n_chunks > 0) { - res.writeHead(status, { "Content-Type": "text/plain", - "Transfer-Encoding": "chunked" }); + res.writeHead(status, { 'Content-Type': 'text/plain', + 'Transfer-Encoding': 'chunked' }); // send body in chunks var len = body.length; var step = Math.floor(len / n_chunks) || 1; - for (var i = 0, n = (n_chunks - 1); i < n; ++i) { + for (i = 0, n = (n_chunks - 1); i < n; ++i) { res.write(body.slice(i * step, i * step + step)); } res.end(body.slice((n_chunks - 1) * step)); } else { var content_length = body.length.toString(); - res.writeHead(status, { "Content-Type": "text/plain", - "Content-Length": content_length }); + res.writeHead(status, { 'Content-Type': 'text/plain', + 'Content-Length': content_length }); res.end(body); } }); -server.listen(port, function () { +server.listen(port, function() { var url = 'http://127.0.0.1:' + port + '/'; var n = process.argv.length - 1; @@ -109,10 +110,10 @@ server.listen(port, function () { }); function dump_mm_stats() { - if (typeof gc != 'function') return; + if (typeof global.gc != 'function') return; var before = process.memoryUsage(); - for (var i = 0; i < 10; ++i) gc(); + for (var i = 0; i < 10; ++i) global.gc(); var after = process.memoryUsage(); setTimeout(print_stats, 250); // give GC time to settle diff --git a/benchmark/http_simple_cluster.js b/benchmark/http_simple_cluster.js index 9a886f2ee75dab..f48a2a2599a78f 100644 --- a/benchmark/http_simple_cluster.js +++ b/benchmark/http_simple_cluster.js @@ -1,9 +1,11 @@ -var cluster = require('cluster'); -var os = require('os'); +'use strict'; +const cluster = require('cluster'); +const os = require('os'); +const path = require('path'); if (cluster.isMaster) { console.log('master running on pid %d', process.pid); for (var i = 0, n = os.cpus().length; i < n; ++i) cluster.fork(); } else { - require(__dirname + '/http_simple.js'); + require(path.join(__dirname, 'http_simple.js')); } diff --git a/benchmark/idle_clients.js b/benchmark/idle_clients.js index da96b8ac654db4..d294e685224d8b 100644 --- a/benchmark/idle_clients.js +++ b/benchmark/idle_clients.js @@ -1,27 +1,25 @@ -net = require('net'); +'use strict'; +const net = require('net'); var errors = 0, connections = 0; -var lastClose = 0; - -function connect () { - process.nextTick(function () { +function connect() { + process.nextTick(function() { var s = net.Stream(); var gotConnected = false; s.connect(9000); - s.on('connect', function () { + s.on('connect', function() { gotConnected = true; connections++; connect(); }); - s.on('close', function () { + s.on('close', function() { if (gotConnected) connections--; - lastClose = new Date(); }); - s.on('error', function () { + s.on('error', function() { errors++; }); }); @@ -35,15 +33,15 @@ var oldConnections, oldErrors; // Try to start new connections every so often setInterval(connect, 5000); -setInterval(function () { +setInterval(function() { if (oldConnections != connections) { oldConnections = connections; - console.log("CLIENT %d connections: %d", process.pid, connections); + console.log('CLIENT %d connections: %d', process.pid, connections); } if (oldErrors != errors) { oldErrors = errors; - console.log("CLIENT %d errors: %d", process.pid, errors); + console.log('CLIENT %d errors: %d', process.pid, errors); } }, 1000); diff --git a/benchmark/idle_server.js b/benchmark/idle_server.js index 805c988811ea50..78e496690d1d4e 100644 --- a/benchmark/idle_server.js +++ b/benchmark/idle_server.js @@ -1,12 +1,11 @@ 'use strict'; const net = require('net'); -var connections = 0; var errors = 0; -var server = net.Server(function (socket) { +var server = net.Server(function(socket) { - socket.on('error', function () { + socket.on('error', function() { errors++; }); @@ -18,14 +17,14 @@ server.listen(9000); var oldConnections, oldErrors; -setInterval(function () { +setInterval(function() { if (oldConnections != server.connections) { oldConnections = server.connections; - console.log("SERVER %d connections: %d", process.pid, server.connections); + console.log('SERVER %d connections: %d', process.pid, server.connections); } if (oldErrors != errors) { oldErrors = errors; - console.log("SERVER %d errors: %d", process.pid, errors); + console.log('SERVER %d errors: %d', process.pid, errors); } }, 1000); diff --git a/benchmark/misc/child-process-read.js b/benchmark/misc/child-process-read.js index 894dd55d301249..c1a7474aae32c1 100644 --- a/benchmark/misc/child-process-read.js +++ b/benchmark/misc/child-process-read.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var bench = common.createBenchmark(main, { len: [64, 256, 1024, 4096, 32768], diff --git a/benchmark/misc/domain-fn-args.js b/benchmark/misc/domain-fn-args.js index 36e9e900299bb2..e9b24811c81689 100644 --- a/benchmark/misc/domain-fn-args.js +++ b/benchmark/misc/domain-fn-args.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var domain = require('domain'); @@ -11,17 +12,17 @@ var gargs = [1, 2, 3]; function main(conf) { - var args, ret, n = +conf.n; - var arguments = gargs.slice(0, conf.arguments); + var args, n = +conf.n; + var myArguments = gargs.slice(0, conf.arguments); bench.start(); bdomain.enter(); for (var i = 0; i < n; i++) { - if (arguments.length >= 2) { - args = Array.prototype.slice.call(arguments, 1); - ret = fn.apply(this, args); + if (myArguments.length >= 2) { + args = Array.prototype.slice.call(myArguments, 1); + fn.apply(this, args); } else { - ret = fn.call(this); + fn.call(this); } } bdomain.exit(); @@ -40,4 +41,4 @@ function fn(a, b, c) { c = 3; return a + b + c; -} \ No newline at end of file +} diff --git a/benchmark/misc/freelist.js b/benchmark/misc/freelist.js index 76275000b08ffb..7956dc3d6b18c0 100644 --- a/benchmark/misc/freelist.js +++ b/benchmark/misc/freelist.js @@ -22,7 +22,7 @@ function main(conf) { bench.start(); - for (i = 0; i < n; i++){ + for (i = 0; i < n; i++) { // Return all the items to the pool for (j = 0; j < poolSize; j++) { list.free(used[j]); diff --git a/benchmark/misc/function_call/index.js b/benchmark/misc/function_call/index.js index fc8542a068ccd6..04f5627093893e 100644 --- a/benchmark/misc/function_call/index.js +++ b/benchmark/misc/function_call/index.js @@ -2,6 +2,7 @@ // relative to a comparable C++ function. // Reports millions of calls per second. // Note that JS speed goes up, while cxx speed stays about the same. +'use strict'; var assert = require('assert'); var common = require('../../common.js'); @@ -27,7 +28,7 @@ assert(js() === cxx()); var bench = common.createBenchmark(main, { type: ['js', 'cxx'], - millions: [1,10,50] + millions: [1, 10, 50] }); function main(conf) { diff --git a/benchmark/misc/module-loader.js b/benchmark/misc/module-loader.js index e53bc4d801164b..1df7a74cbe77e1 100644 --- a/benchmark/misc/module-loader.js +++ b/benchmark/misc/module-loader.js @@ -1,7 +1,7 @@ +'use strict'; var fs = require('fs'); var path = require('path'); var common = require('../common.js'); -var packageJson = '{"main": "index.js"}'; var tmpDirectory = path.join(__dirname, '..', 'tmp'); var benchmarkDirectory = path.join(tmpDirectory, 'nodejs-benchmark-module'); @@ -18,8 +18,14 @@ function main(conf) { var n = +conf.thousands * 1e3; for (var i = 0; i <= n; i++) { fs.mkdirSync(benchmarkDirectory + i); - fs.writeFileSync(benchmarkDirectory + i + '/package.json', '{"main": "index.js"}'); - fs.writeFileSync(benchmarkDirectory + i + '/index.js', 'module.exports = "";'); + fs.writeFileSync( + benchmarkDirectory + i + '/package.json', + '{"main": "index.js"}' + ); + fs.writeFileSync( + benchmarkDirectory + i + '/index.js', + 'module.exports = "";' + ); } measure(n); @@ -38,7 +44,7 @@ function rmrf(location) { var things = fs.readdirSync(location); things.forEach(function(thing) { var cur = path.join(location, thing), - isDirectory = fs.statSync(cur).isDirectory(); + isDirectory = fs.statSync(cur).isDirectory(); if (isDirectory) { rmrf(cur); return; diff --git a/benchmark/misc/next-tick-breadth.js b/benchmark/misc/next-tick-breadth.js index 652408144373f6..87d130f3a7e102 100644 --- a/benchmark/misc/next-tick-breadth.js +++ b/benchmark/misc/next-tick-breadth.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var bench = common.createBenchmark(main, { diff --git a/benchmark/misc/next-tick-depth.js b/benchmark/misc/next-tick-depth.js index 8a2c8e0a6ae148..bc513d338d6d8c 100644 --- a/benchmark/misc/next-tick-depth.js +++ b/benchmark/misc/next-tick-depth.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var bench = common.createBenchmark(main, { millions: [2] diff --git a/benchmark/misc/spawn-echo.js b/benchmark/misc/spawn-echo.js index 2b1b989e679b96..7c9e851aacb641 100644 --- a/benchmark/misc/spawn-echo.js +++ b/benchmark/misc/spawn-echo.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var bench = common.createBenchmark(main, { thousands: [1] diff --git a/benchmark/misc/startup.js b/benchmark/misc/startup.js index aa5b4420f65903..34604911d250f3 100644 --- a/benchmark/misc/startup.js +++ b/benchmark/misc/startup.js @@ -1,10 +1,8 @@ +'use strict'; var common = require('../common.js'); var spawn = require('child_process').spawn; var path = require('path'); var emptyJsFile = path.resolve(__dirname, '../../test/fixtures/semicolon.js'); -var starts = 100; -var i = 0; -var start; var bench = common.createBenchmark(startNode, { dur: [1] @@ -14,7 +12,6 @@ function startNode(conf) { var dur = +conf.dur; var go = true; var starts = 0; - var open = 0; setTimeout(function() { go = false; diff --git a/benchmark/misc/string-creation.js b/benchmark/misc/string-creation.js index 74dabd66c02501..59fb1b52b4ec12 100644 --- a/benchmark/misc/string-creation.js +++ b/benchmark/misc/string-creation.js @@ -1,8 +1,9 @@ +'use strict'; var common = require('../common.js'); var bench = common.createBenchmark(main, { millions: [100] -}) +}); function main(conf) { var n = +conf.millions * 1e6; @@ -10,7 +11,7 @@ function main(conf) { var s; for (var i = 0; i < n; i++) { s = '01234567890'; - s[1] = "a"; + s[1] = 'a'; } bench.end(n / 1e6); } diff --git a/benchmark/misc/string-decoder.js b/benchmark/misc/string-decoder.js index 14563cee0d7754..b10b0a6e9cbd48 100644 --- a/benchmark/misc/string-decoder.js +++ b/benchmark/misc/string-decoder.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var StringDecoder = require('string_decoder').StringDecoder; @@ -21,6 +22,7 @@ function main(conf) { var chunks = []; var str = ''; var isBase64 = (encoding === 'base64-ascii' || encoding === 'base64-utf8'); + var i; if (encoding === 'ascii' || encoding === 'base64-ascii') alpha = ASC_ALPHA; @@ -31,7 +33,7 @@ function main(conf) { var sd = new StringDecoder(isBase64 ? 'base64' : encoding); - for (var i = 0; i < inLen; ++i) { + for (i = 0; i < inLen; ++i) { if (i > 0 && (i % chunkLen) === 0 && !isBase64) { chunks.push(new Buffer(str, encoding)); str = ''; @@ -52,7 +54,7 @@ function main(conf) { var nChunks = chunks.length; bench.start(); - for (var i = 0; i < n; ++i) { + for (i = 0; i < n; ++i) { for (var j = 0; j < nChunks; ++j) sd.write(chunks[j]); } diff --git a/benchmark/misc/timers.js b/benchmark/misc/timers.js index 23f571bb4528a1..13b18fffc5ead7 100644 --- a/benchmark/misc/timers.js +++ b/benchmark/misc/timers.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var bench = common.createBenchmark(main, { diff --git a/benchmark/misc/url.js b/benchmark/misc/url.js index 6c2799b6cb92b2..4b65300a9c580d 100644 --- a/benchmark/misc/url.js +++ b/benchmark/misc/url.js @@ -1,4 +1,5 @@ -var url = require('url') +'use strict'; +var url = require('url'); var n = 25 * 100; var urls = [ @@ -20,7 +21,7 @@ benchmark('parse()', url.parse); benchmark('format()', url.format); paths.forEach(function(p) { benchmark('resolve("' + p + '")', function(u) { - url.resolve(u, p) + url.resolve(u, p); }); }); diff --git a/benchmark/misc/v8-bench.js b/benchmark/misc/v8-bench.js index 0eb95aa9e2b2bc..0b9a5139ba23cf 100644 --- a/benchmark/misc/v8-bench.js +++ b/benchmark/misc/v8-bench.js @@ -1,4 +1,5 @@ // compare with "google-chrome deps/v8/benchmarks/run.html" +'use strict'; var fs = require('fs'); var path = require('path'); var vm = require('vm'); @@ -19,4 +20,4 @@ global.load = function(filename) { global.RegExp = $RegExp; }; -load('run.js'); +global.load('run.js'); diff --git a/benchmark/net/dgram.js b/benchmark/net/dgram.js index 6a0c5501c62c8e..fed5b873929b98 100644 --- a/benchmark/net/dgram.js +++ b/benchmark/net/dgram.js @@ -1,3 +1,4 @@ +'use strict'; // test UDP send/recv throughput var common = require('../common.js'); @@ -18,7 +19,6 @@ var len; var num; var type; var chunk; -var encoding; function main(conf) { dur = +conf.dur; diff --git a/benchmark/net/net-c2s-cork.js b/benchmark/net/net-c2s-cork.js index 5f8e0fa4357b99..5d1c8a7495ead9 100644 --- a/benchmark/net/net-c2s-cork.js +++ b/benchmark/net/net-c2s-cork.js @@ -1,4 +1,5 @@ // test the speed of .pipe() with sockets +'use strict'; var common = require('../common.js'); var PORT = common.PORT; @@ -35,7 +36,6 @@ function main(conf) { break; default: throw new Error('invalid type: ' + type); - break; } server(); @@ -77,8 +77,8 @@ function server() { socket.on('connect', function() { bench.start(); - socket.on('drain', send) - send() + socket.on('drain', send); + send(); setTimeout(function() { var bytes = writer.received; @@ -88,7 +88,7 @@ function server() { function send() { socket.cork(); - while(socket.write(chunk, encoding)) {} + while (socket.write(chunk, encoding)) {} socket.uncork(); } }); diff --git a/benchmark/net/net-c2s.js b/benchmark/net/net-c2s.js index 49de7c77c9265c..370ff4f138cafd 100644 --- a/benchmark/net/net-c2s.js +++ b/benchmark/net/net-c2s.js @@ -1,4 +1,5 @@ // test the speed of .pipe() with sockets +'use strict'; var common = require('../common.js'); var PORT = common.PORT; @@ -35,7 +36,6 @@ function main(conf) { break; default: throw new Error('invalid type: ' + type); - break; } server(); diff --git a/benchmark/net/net-pipe.js b/benchmark/net/net-pipe.js index 2a5ed8e483659e..ea8af249a35b50 100644 --- a/benchmark/net/net-pipe.js +++ b/benchmark/net/net-pipe.js @@ -1,4 +1,5 @@ // test the speed of .pipe() with sockets +'use strict'; var common = require('../common.js'); var PORT = common.PORT; @@ -35,7 +36,6 @@ function main(conf) { break; default: throw new Error('invalid type: ' + type); - break; } server(); diff --git a/benchmark/net/net-s2c.js b/benchmark/net/net-s2c.js index 79e22494a7b8ed..af40d8d58d8852 100644 --- a/benchmark/net/net-s2c.js +++ b/benchmark/net/net-s2c.js @@ -1,4 +1,5 @@ // test the speed of .pipe() with sockets +'use strict'; var common = require('../common.js'); var PORT = common.PORT; @@ -35,7 +36,6 @@ function main(conf) { break; default: throw new Error('invalid type: ' + type); - break; } server(); diff --git a/benchmark/net/tcp-raw-c2s.js b/benchmark/net/tcp-raw-c2s.js index 0039313f5235ad..e13af85c6774dd 100644 --- a/benchmark/net/tcp-raw-c2s.js +++ b/benchmark/net/tcp-raw-c2s.js @@ -1,5 +1,6 @@ // In this benchmark, we connect a client to the server, and write // as many bytes as we can in the specified time (default = 10s) +'use strict'; var common = require('../common.js'); var util = require('util'); @@ -89,7 +90,6 @@ function client() { break; default: throw new Error('invalid type: ' + type); - break; } var clientHandle = new TCP(); diff --git a/benchmark/net/tcp-raw-pipe.js b/benchmark/net/tcp-raw-pipe.js index 1504d11db5fa53..c05c816855e7a6 100644 --- a/benchmark/net/tcp-raw-pipe.js +++ b/benchmark/net/tcp-raw-pipe.js @@ -1,5 +1,6 @@ // In this benchmark, we connect a client to the server, and write // as many bytes as we can in the specified time (default = 10s) +'use strict'; var common = require('../common.js'); var util = require('util'); @@ -87,7 +88,6 @@ function client() { break; default: throw new Error('invalid type: ' + type); - break; } var clientHandle = new TCP(); diff --git a/benchmark/net/tcp-raw-s2c.js b/benchmark/net/tcp-raw-s2c.js index 502586c2a05e29..822a74c679db12 100644 --- a/benchmark/net/tcp-raw-s2c.js +++ b/benchmark/net/tcp-raw-s2c.js @@ -1,5 +1,6 @@ // In this benchmark, we connect a client to the server, and write // as many bytes as we can in the specified time (default = 10s) +'use strict'; var common = require('../common.js'); var util = require('util'); @@ -61,7 +62,6 @@ function server() { break; default: throw new Error('invalid type: ' + type); - break; } clientHandle.readStart(); diff --git a/benchmark/path/basename.js b/benchmark/path/basename.js index 57d9492746b32c..6c710dbb58ceb6 100644 --- a/benchmark/path/basename.js +++ b/benchmark/path/basename.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var path = require('path'); var v8 = require('v8'); diff --git a/benchmark/path/dirname.js b/benchmark/path/dirname.js index e95adf28811a4e..4a9c04158cdee6 100644 --- a/benchmark/path/dirname.js +++ b/benchmark/path/dirname.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var path = require('path'); var v8 = require('v8'); diff --git a/benchmark/path/extname.js b/benchmark/path/extname.js index c655ee7e3e160a..4f7c6b542d21c4 100644 --- a/benchmark/path/extname.js +++ b/benchmark/path/extname.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var path = require('path'); var v8 = require('v8'); diff --git a/benchmark/path/format.js b/benchmark/path/format.js index bc77f888116963..478a30cbaedbd2 100644 --- a/benchmark/path/format.js +++ b/benchmark/path/format.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var path = require('path'); var v8 = require('v8'); diff --git a/benchmark/path/isAbsolute.js b/benchmark/path/isAbsolute.js index d4c79b99cdbeb7..0d412f925388c6 100644 --- a/benchmark/path/isAbsolute.js +++ b/benchmark/path/isAbsolute.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var path = require('path'); var v8 = require('v8'); diff --git a/benchmark/path/join.js b/benchmark/path/join.js index 58f4dc3e1e9e44..0262e25d249cb0 100644 --- a/benchmark/path/join.js +++ b/benchmark/path/join.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var path = require('path'); var v8 = require('v8'); diff --git a/benchmark/path/normalize.js b/benchmark/path/normalize.js index 6f7f05e4f9e1c8..56a637f401c0cc 100644 --- a/benchmark/path/normalize.js +++ b/benchmark/path/normalize.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var path = require('path'); var v8 = require('v8'); diff --git a/benchmark/path/parse.js b/benchmark/path/parse.js index f3fbb2a1f5c98f..2afc143090c6c8 100644 --- a/benchmark/path/parse.js +++ b/benchmark/path/parse.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var path = require('path'); var v8 = require('v8'); diff --git a/benchmark/path/relative.js b/benchmark/path/relative.js index d61c3961a62d8b..0a72a2ad7bf726 100644 --- a/benchmark/path/relative.js +++ b/benchmark/path/relative.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var path = require('path'); var v8 = require('v8'); diff --git a/benchmark/path/resolve.js b/benchmark/path/resolve.js index 375e8b134ba0ea..5235b94b74d328 100644 --- a/benchmark/path/resolve.js +++ b/benchmark/path/resolve.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var path = require('path'); var v8 = require('v8'); diff --git a/benchmark/querystring/querystring-parse.js b/benchmark/querystring/querystring-parse.js index 6a4d9f5e6169f4..1019a941dfdecb 100644 --- a/benchmark/querystring/querystring-parse.js +++ b/benchmark/querystring/querystring-parse.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var querystring = require('querystring'); var v8 = require('v8'); @@ -27,8 +28,16 @@ function main(conf) { v8.setFlagsFromString('--allow_natives_syntax'); eval('%OptimizeFunctionOnNextCall(querystring.parse)'); - bench.start(); - for (var i = 0; i < n; i += 1) - querystring.parse(input); - bench.end(n); + var i; + if (type !== 'multicharsep') { + bench.start(); + for (i = 0; i < n; i += 1) + querystring.parse(input); + bench.end(n); + } else { + bench.start(); + for (i = 0; i < n; i += 1) + querystring.parse(input, '&&&&&&&&&&'); + bench.end(n); + } } diff --git a/benchmark/querystring/querystring-stringify.js b/benchmark/querystring/querystring-stringify.js index d4bb95c21e5af4..c2f38554166aa4 100644 --- a/benchmark/querystring/querystring-stringify.js +++ b/benchmark/querystring/querystring-stringify.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var querystring = require('querystring'); var v8 = require('v8'); diff --git a/benchmark/report-startup-memory.js b/benchmark/report-startup-memory.js index 14e56231ec2ddd..6d796307f4f437 100644 --- a/benchmark/report-startup-memory.js +++ b/benchmark/report-startup-memory.js @@ -1 +1,2 @@ +'use strict'; console.log(process.memoryUsage().rss); diff --git a/benchmark/static_http_server.js b/benchmark/static_http_server.js index b3a83785e3792f..804f83c208bb39 100644 --- a/benchmark/static_http_server.js +++ b/benchmark/static_http_server.js @@ -1,9 +1,10 @@ +'use strict'; var http = require('http'); var concurrency = 30; var port = 12346; var n = 700; -var bytes = 1024*5; +var bytes = 1024 * 5; var requests = 0; var responses = 0; @@ -19,7 +20,7 @@ var server = http.createServer(function(req, res) { 'Content-Length': body.length }); res.end(body); -}) +}); server.listen(port, function() { var agent = new http.Agent(); diff --git a/benchmark/tls/throughput.js b/benchmark/tls/throughput.js index 442eba338ed643..7b545267ace7fe 100644 --- a/benchmark/tls/throughput.js +++ b/benchmark/tls/throughput.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var bench = common.createBenchmark(main, { dur: [5], @@ -30,7 +31,7 @@ function main(conf) { encoding = 'ascii'; break; case 'utf': - chunk = new Array(size/2 + 1).join('ü'); + chunk = new Array(size / 2 + 1).join('ü'); encoding = 'utf8'; break; default: @@ -44,16 +45,16 @@ function main(conf) { server = tls.createServer(options, onConnection); setTimeout(done, dur * 1000); + var conn; server.listen(common.PORT, function() { var opt = { port: common.PORT, rejectUnauthorized: false }; - var conn = tls.connect(opt, function() { + conn = tls.connect(opt, function() { bench.start(); conn.on('drain', write); write(); }); function write() { - var i = 0; while (false !== conn.write(chunk, encoding)); } }); @@ -68,7 +69,8 @@ function main(conf) { function done() { var mbits = (received * 8) / (1024 * 1024); bench.end(mbits); - conn.destroy(); + if (conn) + conn.destroy(); server.close(); } } diff --git a/benchmark/tls/tls-connect.js b/benchmark/tls/tls-connect.js index 96c9c5ab275f9d..a265989e04db24 100644 --- a/benchmark/tls/tls-connect.js +++ b/benchmark/tls/tls-connect.js @@ -1,7 +1,7 @@ -var assert = require('assert'), - fs = require('fs'), - path = require('path'), - tls = require('tls'); +'use strict'; +var fs = require('fs'), + path = require('path'), + tls = require('tls'); var common = require('../common.js'); var bench = common.createBenchmark(main, { @@ -21,10 +21,10 @@ function main(conf) { concurrency = +conf.concurrency; var cert_dir = path.resolve(__dirname, '../../test/fixtures'), - 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') ], - ciphers: 'AES256-GCM-SHA384' }; + 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') ], + ciphers: 'AES256-GCM-SHA384' }; server = tls.createServer(options, onConnection); server.listen(common.PORT, onListening); diff --git a/benchmark/url/url-parse.js b/benchmark/url/url-parse.js index ffa47c4ccd6105..89679548b8f193 100644 --- a/benchmark/url/url-parse.js +++ b/benchmark/url/url-parse.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var url = require('url'); var v8 = require('v8'); diff --git a/benchmark/url/url-resolve.js b/benchmark/url/url-resolve.js index 5f6c1f7600ce4e..18f67e82e30787 100644 --- a/benchmark/url/url-resolve.js +++ b/benchmark/url/url-resolve.js @@ -1,3 +1,4 @@ +'use strict'; var common = require('../common.js'); var url = require('url'); var v8 = require('v8'); diff --git a/benchmark/util/inspect.js b/benchmark/util/inspect.js index 8a59e6b48e54df..3312bd683ba81b 100644 --- a/benchmark/util/inspect.js +++ b/benchmark/util/inspect.js @@ -1,3 +1,4 @@ +'use strict'; var util = require('util'); var common = require('../common.js'); @@ -9,7 +10,7 @@ function main(conf) { bench.start(); for (var i = 0; i < n; i += 1) { - var r = util.inspect({a: 'a', b: 'b', c: 'c', d: 'd'}); + util.inspect({a: 'a', b: 'b', c: 'c', d: 'd'}); } bench.end(n); } diff --git a/vcbuild.bat b/vcbuild.bat index 1a6a0e45c6f678..e955860b8a464e 100644 --- a/vcbuild.bat +++ b/vcbuild.bat @@ -258,7 +258,7 @@ goto jslint :jslint if not defined jslint goto exit echo running jslint -%config%\node tools\eslint\bin\eslint.js lib src test tools\doc tools\eslint-rules --rulesdir tools\eslint-rules +%config%\node tools\eslint\bin\eslint.js benchmark lib src test tools\doc tools\eslint-rules --rulesdir tools\eslint-rules goto exit :create-msvs-files-failed