aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-03-07 19:25:12 +0800
committerGitHub <noreply@github.com>2017-03-07 19:25:12 +0800
commit65c848cc6f13cb5ae3bc1c0fb5fbb320ed2d0200 (patch)
tree1847573960d3136be23dd54fa633a58b95dd1f25 /test
parent8a8a94a596f57981e2cc65ac37921b154a9992b7 (diff)
downloadtracifyjs-65c848cc6f13cb5ae3bc1c0fb5fbb320ed2d0200.tar.gz
tracifyjs-65c848cc6f13cb5ae3bc1c0fb5fbb320ed2d0200.zip
include benchmark.js in test suite (#1564)
- report file sizes and overall run time - exit with non-zero code upon error
Diffstat (limited to 'test')
-rw-r--r--test/benchmark.js45
-rw-r--r--test/mocha/benchmark.js24
2 files changed, 62 insertions, 7 deletions
diff --git a/test/benchmark.js b/test/benchmark.js
index dc176a88..c150e5cf 100644
--- a/test/benchmark.js
+++ b/test/benchmark.js
@@ -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();
+ });
});
});
diff --git a/test/mocha/benchmark.js b/test/mocha/benchmark.js
new file mode 100644
index 00000000..c2c7c02c
--- /dev/null
+++ b/test/mocha/benchmark.js
@@ -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();
+ });
+ });
+ });
+});