[Pkg-javascript-commits] [uglifyjs] 30/228: add benchmark & JetStream tests - `test/benchmark.js` measures performance - `test/jetstream.js` verifies correctness - configurable mangle/compress/output options

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:14 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 7e6331bb397e1dec0a4e15233a2afca3a4e9daff
Author: alexlamsl <alexlamsl at gmail.com>
Date:   Sat Feb 18 19:28:25 2017 +0800

    add benchmark & JetStream tests
    - `test/benchmark.js` measures performance
    - `test/jetstream.js` verifies correctness
    - configurable mangle/compress/output options
    
    closes #1479
---
 test/benchmark.js | 49 +++++++++++++++++++++++++++++++
 test/jetstream.js | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 136 insertions(+)

diff --git a/test/benchmark.js b/test/benchmark.js
new file mode 100644
index 0000000..dc176a8
--- /dev/null
+++ b/test/benchmark.js
@@ -0,0 +1,49 @@
+#! /usr/bin/env node
+// -*- js -*-
+
+"use strict";
+
+var createHash = require("crypto").createHash;
+var fork = require("child_process").fork;
+var args = process.argv.slice(2);
+if (!args.length) {
+    args.push("-mc", "warnings=false");
+}
+args.push("--stats");
+var urls = [
+    "https://code.jquery.com/jquery-3.1.1.js",
+    "https://code.angularjs.org/1.6.1/angular.js",
+    "https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.9.0/math.js",
+    "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js",
+    "https://unpkg.com/react@15.3.2/dist/react.js",
+    "http://builds.emberjs.com/tags/v2.11.0/ember.prod.js",
+    "https://cdn.jsdelivr.net/lodash/4.17.4/lodash.js",
+    "https://cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.js",
+];
+var results = {};
+var remaining = 2 * urls.length;
+function done() {
+    if (!--remaining) {
+        urls.forEach(function(url) {
+            console.log();
+            console.log(url);
+            console.log(results[url].time);
+            console.log("SHA1:", results[url].sha1);
+        });
+    }
+}
+urls.forEach(function(url) {
+    results[url] = { time: "" };
+    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) {
+            results[url].sha1 = data.toString("hex");
+            done();
+        });
+        uglifyjs.stderr.setEncoding("utf8");
+        uglifyjs.stderr.on("data", function(data) {
+            results[url].time += data;
+        }).on("end", done)
+    });
+});
diff --git a/test/jetstream.js b/test/jetstream.js
new file mode 100644
index 0000000..a819538
--- /dev/null
+++ b/test/jetstream.js
@@ -0,0 +1,87 @@
+#! /usr/bin/env node
+// -*- js -*-
+
+"use strict";
+
+var site = "http://browserbench.org/JetStream/";
+if (typeof phantom == "undefined") {
+    // workaround for tty output truncation upon process.exit()
+    [process.stdout, process.stderr].forEach(function(stream){
+        if (stream._handle && stream._handle.setBlocking)
+            stream._handle.setBlocking(true);
+    });
+    var args = process.argv.slice(2);
+    if (!args.length) {
+        args.push("-mc", "warnings=false");
+    }
+    args.push("--stats");
+    var child_process = require("child_process");
+    try {
+        require("phantomjs-prebuilt");
+    } catch(e) {
+        child_process.execSync("npm install phantomjs-prebuilt at 2.1.14");
+    }
+    var http = require("http");
+    var server = http.createServer(function(request, response) {
+        request.resume();
+        var url = decodeURIComponent(request.url.slice(1));
+        var stderr = "";
+        var uglifyjs = child_process.fork("bin/uglifyjs", args, {
+            silent: true
+        }).on("exit", function(code) {
+            console.log("uglifyjs", url.indexOf(site) == 0 ? url.slice(site.length) : url, args.join(" "));
+            console.log(stderr);
+            if (code) throw new Error("uglifyjs failed with code " + code);
+        });
+        uglifyjs.stderr.on("data", function(data) {
+            stderr += data;
+        }).setEncoding("utf8");
+        uglifyjs.stdout.pipe(response);
+        http.get(url, function(res) {
+            res.pipe(uglifyjs.stdin);
+        });
+    }).listen().on("listening", function() {
+        var phantomjs = require("phantomjs-prebuilt");
+        var program = phantomjs.exec(process.argv[1], server.address().port);
+        program.stdout.pipe(process.stdout);
+        program.stderr.pipe(process.stderr);
+        program.on("exit", function(code) {
+            server.close();
+            if (code) throw new Error("JetStream failed!");
+            console.log("JetStream completed successfully.");
+        });
+    });
+    server.timeout = 0;
+} else {
+    var page = require("webpage").create();
+    page.onError = function(msg, trace) {
+        var body = [ msg ];
+        if (trace) trace.forEach(function(t) {
+            body.push("  " + (t.function || "Anonymous function") + " (" + t.file + ":" + t.line + ")");
+        });
+        console.error(body.join("\n"));
+        phantom.exit(1);
+    };
+    var url = "http://localhost:" + require("system").args[1] + "/";
+    page.onResourceRequested = function(requestData, networkRequest) {
+        if (/\.js$/.test(requestData.url))
+            networkRequest.changeUrl(url + encodeURIComponent(requestData.url));
+    }
+    page.onConsoleMessage = function(msg) {
+        if (/Error:/i.test(msg)) {
+            console.error(msg);
+            phantom.exit(1);
+        }
+        console.log(msg);
+        if (~msg.indexOf("Raw results:")) {
+            phantom.exit();
+        }
+    };
+    page.open(site, function(status) {
+        if (status != "success") phantomjs.exit(1);
+        page.evaluate(function() {
+            JetStream.switchToQuick();
+            JetStream.start();
+        });
+    });
+}

-- 
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