forked from redis/node-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff_multi_bench_output.js
executable file
·90 lines (73 loc) · 2.54 KB
/
diff_multi_bench_output.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env node
var colors = require('colors'),
fs = require('fs'),
_ = require('underscore'),
metrics = require('metrics'),
// `node diff_multi_bench_output.js before.txt after.txt`
before = process.argv[2],
after = process.argv[3];
if (!before || !after) {
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('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 total_ops = new metrics.Histogram.createUniformHistogram();
before_lines.forEach(function(b, i) {
var a = after_lines[i];
if (!a || !b || !b.trim() || !a.trim()) {
// console.log('#ignored#', '>'+a+'<', '>'+b+'<');
return;
}
b_words = b.split(' ').filter(is_whitespace);
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 delta = ops[1] - ops[0];
var pct = ((delta / ops[0]) * 100).toPrecision(3);
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, ')');
});
console.log('Mean difference in ops/sec:', humanize_diff(total_ops.mean().toPrecision(6)));
function is_whitespace(s) {
return !!s.trim();
}
function parseInt10(s) {
return parseInt(s, 10);
}
// green if greater than 0, red otherwise
function humanize_diff(num, unit) {
unit = unit || "";
if (num > 0) {
return ('+' + num + unit).green;
}
return ('' + num + unit).red;
}
function command_name(words) {
var line = words.join(' ');
return line.substr(0, line.indexOf(','));
}