Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 9234fe1499a98b0f8443a8b3d8e8f04922edb7e0
Author: Wei Kin Huang <weikin.huang04@gmail.com>
Date:   Fri May 25 16:19:18 2012 -0400

    Perf tests has comparison against last run
  • Loading branch information
weikinhuang committed May 25, 2012
1 parent 3f3b38c commit 41cb98f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
.externalToolBuilders
.buildpath
.project
build/.sizecache.json
build/.coveragecache.json
test/dev.html
build/.*.json
coverage/*
29 changes: 25 additions & 4 deletions build/module/perf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module.exports = (function(root) {

// include the fs mmodule
var fs = require("fs"),
// execute system commands
var exec = require("child_process");
exec = require("child_process");

function lpad(str, len, chr) {
return (Array(len + 1).join(chr || " ") + str).substr(-len);
Expand All @@ -16,17 +18,26 @@ module.exports = (function(root) {
return number[0].replace(/(?=(?:\d{3})+$)(?!\b)/g, ',') + (number[1] ? '.' + number[1] : '');
}

function processUnitTestResults(results, callback) {
function processUnitTestResults(results, prevResults, callback) {
var error = 0;
results.forEach(function(test) {
var message = " ";
var message = " ", prevCompare;
if (test.error) {
message += "\x1B[38;5;160m" + rpad(test.name, 35) + "\x1B[0m";
} else {
message += rpad(test.name, 35);
}
message += lpad(formatNumber(test.hz.toFixed(test.hz < 100 ? 2 : 0)), 12) + " ops/s (\u00B1" + test.stats.rme.toFixed(2) + "%)";
message += " [" + formatNumber(test.count) + "x in " + test.times.cycle.toFixed(3) + "s]";

if(prevResults[test.name]) {
prevCompare = test.hz - prevResults[test.name].hz;
message += " [Vs. ";
message += (prevCompare >= 0 ? "+" : "-") + formatNumber(Math.abs(prevCompare).toFixed(Math.abs(prevCompare) < 100 ? 2 : 0)) + " ops/s";
message += " (" + (prevCompare >= 0 ? "+" : "-") + Math.abs(((test.hz - prevResults[test.name].hz) / test.hz) * 100).toFixed(3) + "%)";
message += "]";
}

callback.log(message);
if (test.error) {
error++;
Expand Down Expand Up @@ -100,8 +111,18 @@ module.exports = (function(root) {
}
callback.print("Running benchmarks with Benchmark.js...");
var tests = [], complete = function(env, results) {
var prevPerfStats = {}, currentPerfStats = {};
if (env !== null && results !== true) {
processUnitTestResults(results, callback);
try {
prevPerfStats = JSON.parse(fs.readFileSync(options.dir.build + "/.perfcache." + env + ".json", "utf8"));
} catch (e) {
}
processUnitTestResults(results, prevPerfStats, callback);
results.forEach(function(test) {
currentPerfStats[test.name] = test;
});
fs.writeFileSync(options.dir.build + "/.perfcache." + env + ".json", JSON.stringify(currentPerfStats, true), "utf8");

}
if (results === true) {
callback.log("\x1B[38;5;160m\u2716 \x1B[0mEnvironment " + env + " not found!");
Expand Down

0 comments on commit 41cb98f

Please sign in to comment.