From 087c43796178733da54bff9e8291a5a312c466f1 Mon Sep 17 00:00:00 2001 From: isaacs Date: Wed, 13 Feb 2013 10:47:29 -0800 Subject: [PATCH] bench: Add --html to compare script --- benchmark/compare.js | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/benchmark/compare.js b/benchmark/compare.js index 05733a1e37..5b4beda3f1 100644 --- a/benchmark/compare.js +++ b/benchmark/compare.js @@ -1,7 +1,9 @@ -var usage = 'node benchmark/compare.js '; +var usage = 'node benchmark/compare.js [--html] [--red|-r] [--green|-g]'; var show = 'both'; var nodes = []; +var html = false; + for (var i = 2; i < process.argv.length; i++) { var arg = process.argv[i]; switch (arg) { @@ -11,12 +13,32 @@ for (var i = 2; i < process.argv.length; i++) { case '--green': case '-g': show = show === 'red' ? 'both' : 'green'; break; + case '--html': + html = true; + break; + case '-h': case '-?': case '--help': + console.log(usage); + process.exit(0); default: nodes.push(arg); break; } } +if (!html) { + var start = ''; + var green = '\033[1;32m'; + var red = '\033[1;31m'; + var reset = '\033[m'; + var end = ''; +} else { + var start = '
';
+  var green = '';
+  var red = '';
+  var reset = '';
+  var end = '
'; +} + var runBench = process.env.NODE_BENCH || 'bench'; if (nodes.length !== 2) @@ -79,11 +101,10 @@ function compare() { // each result is an object with {"foo.js arg=bar":12345,...} // compare each thing, and show which node did the best. // 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 util = require('util'); + console.log(start); + Object.keys(results).map(function(bench) { var res = results[bench]; var n0 = res[nodes[0]]; @@ -113,4 +134,5 @@ function compare() { var dots = ' ' + new Array(Math.max(0, dotLen)).join('.') + ' '; console.log(l + dots + pct); }); + console.log(end); }