Skip to content

Commit

Permalink
include benchmark.js in test suite (#1564)
Browse files Browse the repository at this point in the history
- report file sizes and overall run time
- exit with non-zero code upon error
  • Loading branch information
alexlamsl authored Mar 7, 2017
1 parent 8a8a94a commit 65c848c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
45 changes: 38 additions & 7 deletions test/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,57 @@ var results = {};
var remaining = 2 * urls.length;
function done() {
if (!--remaining) {
var failures = [];
urls.forEach(function(url) {
var info = results[url];
console.log();
console.log(url);
console.log(results[url].time);
console.log("SHA1:", results[url].sha1);
console.log(info.log);
var elapsed = 0;
info.log.replace(/: ([0-9]+\.[0-9]{3})s/g, function(match, time) {
elapsed += parseFloat(time);
});
console.log("Run-time:", elapsed.toFixed(3), "s");
console.log("Original:", info.input, "bytes");
console.log("Uglified:", info.output, "bytes");
console.log("SHA1 sum:", info.sha1);
if (info.code) {
failures.push(url);
}
});
if (failures.length) {
console.error("Benchmark failed:");
failures.forEach(function(url) {
console.error(url);
});
process.exit(1);
}
}
}
urls.forEach(function(url) {
results[url] = { time: "" };
results[url] = {
input: 0,
output: 0,
log: ""
};
require(url.slice(0, url.indexOf(":"))).get(url, function(res) {
var uglifyjs = fork("bin/uglifyjs", args, { silent: true });
res.pipe(uglifyjs.stdin);
uglifyjs.stdout.pipe(createHash("sha1")).on("data", function(data) {
res.on("data", function(data) {
results[url].input += data.length;
}).pipe(uglifyjs.stdin);
uglifyjs.stdout.on("data", function(data) {
results[url].output += data.length;
}).pipe(createHash("sha1")).on("data", function(data) {
results[url].sha1 = data.toString("hex");
done();
});
uglifyjs.stderr.setEncoding("utf8");
uglifyjs.stderr.on("data", function(data) {
results[url].time += data;
}).on("end", done)
results[url].log += data;
});
uglifyjs.on("exit", function(code) {
results[url].code = code;
done();
});
});
});
24 changes: 24 additions & 0 deletions test/mocha/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var assert = require("assert");
var exec = require("child_process").exec;

describe("test/benchmark.js", function() {
this.timeout(120000);
var command = '"' + process.argv[0] + '" test/benchmark.js ';
[
"-b",
"-b bracketize",
"-m",
"-mc passes=3",
"-mc passes=3,toplevel",
"-mc passes=3,unsafe",
"-mc keep_fargs=false,passes=3",
"-mc keep_fargs=false,passes=3,pure_getters,unsafe,unsafe_comps,unsafe_math,unsafe_proto",
].forEach(function(args) {
it("Should pass with options " + args, function(done) {
exec(command + args, function(err) {
if (err) throw err;
done();
});
});
});
});

0 comments on commit 65c848c

Please sign in to comment.