You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Update benchmark and diff output
This commit is contained in:
@@ -1,50 +1,55 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
/* jshint -W079: Ignore redefinitions (before & after) */
|
||||
var fs = require('fs');
|
||||
var metrics = require('metrics');
|
||||
// `node diff_multi_bench_output.js beforeBench.txt afterBench.txt`
|
||||
var file1 = process.argv[2];
|
||||
var file2 = process.argv[3];
|
||||
|
||||
var fs = require('fs'),
|
||||
metrics = require('metrics'),
|
||||
|
||||
// `node diff_multi_bench_output.js before.txt after.txt`
|
||||
before = process.argv[2],
|
||||
after = process.argv[3];
|
||||
|
||||
if (!before || !after) {
|
||||
if (!file1 || !file2) {
|
||||
console.log('Please supply two file arguments:');
|
||||
var n = __filename;
|
||||
n = n.substring(n.lastIndexOf('/', n.length));
|
||||
console.log(' ./' + n + ' multiBenchBefore.txt multiBenchAfter.txt');
|
||||
console.log('To generate multiBenchBefore.txt, run');
|
||||
console.log(' node multi_bench.js > multiBenchBefore.txt');
|
||||
console.log(' node .' + n + ' benchBefore.txt benchAfter.txt\n');
|
||||
console.log('To generate the benchmark files, run');
|
||||
console.log(' npm run benchmark > benchBefore.txt\n');
|
||||
console.log('Thank you for benchmarking responsibly.');
|
||||
return;
|
||||
}
|
||||
|
||||
var before_lines = fs.readFileSync(before, 'utf8').split('\n'),
|
||||
after_lines = fs.readFileSync(after, 'utf8').split('\n');
|
||||
|
||||
console.log('Comparing before,', before.green, '(', before_lines.length,
|
||||
'lines)', 'to after,', after.green, '(', after_lines.length, 'lines)');
|
||||
|
||||
var before_lines = fs.readFileSync(file1, 'utf8').split('\n');
|
||||
var after_lines = fs.readFileSync(file2, 'utf8').split('\n');
|
||||
var total_ops = new metrics.Histogram.createUniformHistogram();
|
||||
|
||||
console.log('Comparing before,', file1, '(', before_lines.length, 'lines)', 'to after,', file2, '(', after_lines.length, 'lines)');
|
||||
|
||||
function is_whitespace(s) {
|
||||
return !!s.trim();
|
||||
}
|
||||
|
||||
function parseInt10(s) {
|
||||
return parseInt(s, 10);
|
||||
function pad(input, len, chr, right) {
|
||||
var str = input.toString();
|
||||
chr = chr || ' ';
|
||||
|
||||
if (right) {
|
||||
while (str.length < len) {
|
||||
str += chr;
|
||||
}
|
||||
} else {
|
||||
while (str.length < len) {
|
||||
str = chr + str;
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
// green if greater than 0, red otherwise
|
||||
function humanize_diff(num, unit) {
|
||||
function humanize_diff(num, unit, toFixed) {
|
||||
unit = unit || '';
|
||||
if (num > 0) {
|
||||
return ('+' + num + unit).green;
|
||||
return ' +' + pad(num.toFixed(toFixed || 0) + unit, 7);
|
||||
}
|
||||
return ('' + num + unit).red;
|
||||
return ' -' + pad(Math.abs(num).toFixed(toFixed || 0) + unit, 7);
|
||||
}
|
||||
|
||||
function command_name(words) {
|
||||
@@ -58,35 +63,33 @@ before_lines.forEach(function(b, i) {
|
||||
// console.log('#ignored#', '>'+a+'<', '>'+b+'<');
|
||||
return;
|
||||
}
|
||||
|
||||
var b_words = b.split(' ').filter(is_whitespace);
|
||||
var a_words = a.split(' ').filter(is_whitespace);
|
||||
|
||||
var ops =
|
||||
[b_words, a_words]
|
||||
.map(function(words) {
|
||||
// console.log(words);
|
||||
return parseInt10(words.slice(-2, -1));
|
||||
}).filter(function(num) {
|
||||
var isNaN = !num && num !== 0;
|
||||
return !isNaN;
|
||||
});
|
||||
if (ops.length !== 2) return;
|
||||
|
||||
var ops = [b_words, a_words].map(function(words) {
|
||||
// console.log(words);
|
||||
return words.slice(-2, -1) | 0;
|
||||
}).filter(function(num) {
|
||||
var isNaN = !num && num !== 0;
|
||||
return !isNaN;
|
||||
});
|
||||
if (ops.length !== 2) {
|
||||
return;
|
||||
}
|
||||
var delta = ops[1] - ops[0];
|
||||
var pct = ((delta / ops[0]) * 100).toPrecision(3);
|
||||
|
||||
var pct = +((delta / ops[0]) * 100);
|
||||
ops[0] = pad(ops[0], 6);
|
||||
ops[1] = pad(ops[1], 6);
|
||||
total_ops.update(delta);
|
||||
|
||||
delta = humanize_diff(delta);
|
||||
pct = humanize_diff(pct, '%');
|
||||
console.log(
|
||||
// name of test
|
||||
command_name(a_words) === command_name(b_words) ?
|
||||
command_name(a_words) + ':' :
|
||||
'404:',
|
||||
// results of test
|
||||
ops.join(' -> '), 'ops/sec (∆', delta, pct, ')');
|
||||
var small_delta = pct < 3 && pct > -3;
|
||||
// Let's mark differences above 20% bold
|
||||
var big_delta = pct > 20 || pct < -20 ? ';1' : '';
|
||||
pct = humanize_diff(pct, '', 2) + '%';
|
||||
var str = pad((command_name(a_words) === command_name(b_words) ? command_name(a_words) + ':' : '404:'), 14, false, true) +
|
||||
(pad(ops.join(' -> '), 15) + ' ops/sec (∆' + delta + pct + ')');
|
||||
str = (small_delta ? '' : (/-[^>]/.test(str) ? '\x1b[31' : '\x1b[32') + big_delta + 'm') + str + '\x1b[0m';
|
||||
console.log(str);
|
||||
});
|
||||
|
||||
console.log('Mean difference in ops/sec:', humanize_diff(total_ops.mean().toPrecision(6)));
|
||||
console.log('Mean difference in ops/sec:', humanize_diff(total_ops.mean(), '', 1));
|
||||
|
Reference in New Issue
Block a user