[Pkg-javascript-commits] [uglifyjs] 87/228: include benchmark.js in test suite (#1564)
Jonas Smedegaard
dr at jones.dk
Sat Apr 15 14:25:19 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository uglifyjs.
commit 65c848cc6f13cb5ae3bc1c0fb5fbb320ed2d0200
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Tue Mar 7 19:25:12 2017 +0800
include benchmark.js in test suite (#1564)
- report file sizes and overall run time
- exit with non-zero code upon error
---
test/benchmark.js | 45 ++++++++++++++++++++++++++++++++++++++-------
test/mocha/benchmark.js | 24 ++++++++++++++++++++++++
2 files changed, 62 insertions(+), 7 deletions(-)
diff --git a/test/benchmark.js b/test/benchmark.js
index dc176a8..c150e5c 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 0000000..c2c7c02
--- /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();
+ });
+ });
+ });
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list