Browse Source

bench: Add --html to compare script

v0.9.11-release
isaacs 12 years ago
parent
commit
087c437961
  1. 30
      benchmark/compare.js

30
benchmark/compare.js

@ -1,7 +1,9 @@
var usage = 'node benchmark/compare.js <node-binary1> <node-binary2>'; var usage = 'node benchmark/compare.js <node-binary1> <node-binary2> [--html] [--red|-r] [--green|-g]';
var show = 'both'; var show = 'both';
var nodes = []; var nodes = [];
var html = false;
for (var i = 2; i < process.argv.length; i++) { for (var i = 2; i < process.argv.length; i++) {
var arg = process.argv[i]; var arg = process.argv[i];
switch (arg) { switch (arg) {
@ -11,12 +13,32 @@ for (var i = 2; i < process.argv.length; i++) {
case '--green': case '-g': case '--green': case '-g':
show = show === 'red' ? 'both' : 'green'; show = show === 'red' ? 'both' : 'green';
break; break;
case '--html':
html = true;
break;
case '-h': case '-?': case '--help':
console.log(usage);
process.exit(0);
default: default:
nodes.push(arg); nodes.push(arg);
break; break;
} }
} }
if (!html) {
var start = '';
var green = '\033[1;32m';
var red = '\033[1;31m';
var reset = '\033[m';
var end = '';
} else {
var start = '<pre style="background-color:#333;color:#eee">';
var green = '<span style="background-color:#0f0;color:#000">';
var red = '<span style="background-color:#f00">';
var reset = '</span>';
var end = '</pre>';
}
var runBench = process.env.NODE_BENCH || 'bench'; var runBench = process.env.NODE_BENCH || 'bench';
if (nodes.length !== 2) if (nodes.length !== 2)
@ -79,11 +101,10 @@ function compare() {
// each result is an object with {"foo.js arg=bar":12345,...} // each result is an object with {"foo.js arg=bar":12345,...}
// compare each thing, and show which node did the best. // compare each thing, and show which node did the best.
// node[0] is shown in green, node[1] shown in red. // node[0] is shown in green, node[1] shown in red.
var green = '\033[1;32m';
var red = '\033[1;31m';
var reset = '\033[m';
var maxLen = -Infinity; var maxLen = -Infinity;
var util = require('util'); var util = require('util');
console.log(start);
Object.keys(results).map(function(bench) { Object.keys(results).map(function(bench) {
var res = results[bench]; var res = results[bench];
var n0 = res[nodes[0]]; var n0 = res[nodes[0]];
@ -113,4 +134,5 @@ function compare() {
var dots = ' ' + new Array(Math.max(0, dotLen)).join('.') + ' '; var dots = ' ' + new Array(Math.max(0, dotLen)).join('.') + ' ';
console.log(l + dots + pct); console.log(l + dots + pct);
}); });
console.log(end);
} }

Loading…
Cancel
Save