Skip to content

Commit

Permalink
tools,benchmark: increase lint compliance
Browse files Browse the repository at this point in the history
In the hopes of soon having the benchmark code linted, this change
groups all the likely non-controversial lint-compliance changes such as
indentation, semi-colon usage, and single-vs.-double quotation marks.

Other lint rules may have subtle performance implications in the V8
currently shipped with Node.js. Those changes will require more careful
review and will be in a separate change.

PR-URL: #5773
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
  • Loading branch information
Trott authored and Myles Borins committed Mar 21, 2016
1 parent 7749644 commit a0ca8e3
Show file tree
Hide file tree
Showing 45 changed files with 118 additions and 153 deletions.
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-bytelength.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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);
}
Expand Down
8 changes: 4 additions & 4 deletions benchmark/buffers/buffer-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,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);
Expand Down
16 changes: 8 additions & 8 deletions benchmark/buffers/buffer-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ 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);
}

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);
Expand Down
16 changes: 7 additions & 9 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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;
}
Expand All @@ -48,7 +48,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);
}
}

Expand Down Expand Up @@ -86,7 +86,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;
Expand Down Expand Up @@ -120,7 +120,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];
Expand All @@ -140,8 +140,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) {
Expand Down Expand Up @@ -203,7 +201,7 @@ function parseOpts(options) {
});
}
return num === 0 ? conf : null;
};
}

Benchmark.prototype.start = function() {
if (this._started)
Expand All @@ -221,8 +219,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);
};

Expand Down
2 changes: 1 addition & 1 deletion benchmark/crypto/aes-gcm-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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();
}

Expand Down
1 change: 0 additions & 1 deletion benchmark/crypto/cipher-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ function legacyWrite(alice, bob, message, encoding, writes) {
written += dec.length;
dec = bob.final();
written += dec.length;
var bits = written * 8;
var gbits = written / (1024 * 1024 * 1024);
bench.end(gbits);
}
3 changes: 0 additions & 3 deletions benchmark/crypto/hash-stream-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ function main(conf) {
api = 'legacy';
}

var crypto = require('crypto');
var assert = require('assert');

var message;
var encoding;
switch (conf.type) {
Expand Down
3 changes: 0 additions & 3 deletions benchmark/crypto/hash-stream-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ function main(conf) {
api = 'legacy';
}

var crypto = require('crypto');
var assert = require('assert');

var message;
var encoding;
switch (conf.type) {
Expand Down
3 changes: 1 addition & 2 deletions benchmark/crypto/rsa-encrypt-decrypt-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var bench = common.createBenchmark(main, {
});

function main(conf) {
var crypto = require('crypto');
var message = (new Buffer(conf.len)).fill('b');

bench.start();
Expand All @@ -38,7 +37,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);
Expand Down
4 changes: 1 addition & 3 deletions benchmark/crypto/rsa-sign-verify-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,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();
Expand All @@ -36,7 +35,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);

Expand All @@ -45,7 +43,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();

Expand Down
1 change: 0 additions & 1 deletion benchmark/events/ee-emit-multi-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,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() {});
Expand Down
2 changes: 1 addition & 1 deletion benchmark/events/ee-listener-count-on-prototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,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);
}
2 changes: 1 addition & 1 deletion benchmark/events/ee-listeners-many.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,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);
}
2 changes: 1 addition & 1 deletion benchmark/events/ee-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,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);
}
5 changes: 2 additions & 3 deletions benchmark/fs-write-stream-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ function runTest(dur, size, type) {
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',
Expand Down
2 changes: 1 addition & 1 deletion benchmark/fs/read-stream-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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) {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/fs/write-stream-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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:
Expand Down
7 changes: 3 additions & 4 deletions benchmark/http/_chunky_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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');
Expand Down Expand Up @@ -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';
Expand All @@ -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)) {
Expand Down
1 change: 0 additions & 1 deletion benchmark/http/chunked.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// Verify that our assumptions are valid.

var common = require('../common.js');
var PORT = common.PORT;

var bench = common.createBenchmark(main, {
num: [1, 4, 8, 16],
Expand Down
1 change: 0 additions & 1 deletion benchmark/http/end-vs-write-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// Verify that our assumptions are valid.

var common = require('../common.js');
var PORT = common.PORT;

var bench = common.createBenchmark(main, {
type: ['asc', 'utf', 'buf'],
Expand Down
12 changes: 6 additions & 6 deletions benchmark/http/http_server_for_chunky_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

1 change: 0 additions & 1 deletion benchmark/http/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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;
Expand Down
10 changes: 5 additions & 5 deletions benchmark/http_bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,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 + ']';
Expand All @@ -47,7 +47,7 @@ function startMaster() {

var forkCount = 0;

cluster.on('online', function () {
cluster.on('online', function() {
forkCount = forkCount + 1;
if (forkCount === ~~options.servers) {
var args = [
Expand Down
2 changes: 1 addition & 1 deletion benchmark/http_server_lag.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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);
Expand Down
Loading

0 comments on commit a0ca8e3

Please sign in to comment.