2017-02-18 11:28:25 +00:00
|
|
|
#! /usr/bin/env node
|
|
|
|
|
// -*- js -*-
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
2022-11-22 17:57:16 +00:00
|
|
|
require("../tools/tty");
|
2023-08-29 22:04:08 +00:00
|
|
|
let createHash = require("crypto").createHash;
|
|
|
|
|
let fetch = require("./fetch");
|
|
|
|
|
let spawn = require("child_process").spawn;
|
|
|
|
|
let zlib = require("zlib");
|
|
|
|
|
let args = process.argv.slice(2);
|
2020-04-14 02:13:42 +00:00
|
|
|
if (!args.length) args.push("-mc");
|
2020-05-09 01:58:03 +00:00
|
|
|
args.unshift("bin/uglifyjs");
|
2020-05-15 15:57:50 +00:00
|
|
|
args.push("--timings");
|
2023-08-29 22:04:08 +00:00
|
|
|
let urls = [
|
2019-10-10 17:00:09 +00:00
|
|
|
"https://code.jquery.com/jquery-3.4.1.js",
|
|
|
|
|
"https://code.angularjs.org/1.7.8/angular.js",
|
|
|
|
|
"https://unpkg.com/mathjs@6.2.3/dist/math.js",
|
2017-02-18 11:28:25 +00:00
|
|
|
"https://unpkg.com/react@15.3.2/dist/react.js",
|
2021-06-22 16:35:50 +00:00
|
|
|
"https://cdnjs.cloudflare.com/ajax/libs/d3/6.7.0/d3.js",
|
2022-02-18 20:27:17 +00:00
|
|
|
"https://cdnjs.cloudflare.com/ajax/libs/antd/4.18.7/antd.js",
|
2019-10-10 17:00:09 +00:00
|
|
|
"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js",
|
|
|
|
|
"https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.js",
|
|
|
|
|
"https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.12.2/ember.prod.js",
|
|
|
|
|
"https://raw.githubusercontent.com/kangax/html-minifier/v4.0.0/dist/htmlminifier.js",
|
2017-02-18 11:28:25 +00:00
|
|
|
];
|
|
|
|
|
var results = {};
|
|
|
|
|
var remaining = 2 * urls.length;
|
|
|
|
|
function done() {
|
|
|
|
|
if (!--remaining) {
|
2017-03-07 11:25:12 +00:00
|
|
|
var failures = [];
|
2018-02-26 03:46:26 +00:00
|
|
|
var sum = { input: 0, output: 0, gzip: 0 };
|
2017-02-18 11:28:25 +00:00
|
|
|
urls.forEach(function(url) {
|
2017-03-07 11:25:12 +00:00
|
|
|
var info = results[url];
|
2017-02-18 11:28:25 +00:00
|
|
|
console.log();
|
|
|
|
|
console.log(url);
|
2017-05-24 23:15:55 +00:00
|
|
|
console.log(info.log);
|
2017-03-07 11:25:12 +00:00
|
|
|
console.log("Original:", info.input, "bytes");
|
|
|
|
|
console.log("Uglified:", info.output, "bytes");
|
2017-07-08 17:44:59 +00:00
|
|
|
console.log("GZipped: ", info.gzip, "bytes");
|
2017-03-07 11:25:12 +00:00
|
|
|
console.log("SHA1 sum:", info.sha1);
|
|
|
|
|
if (info.code) {
|
|
|
|
|
failures.push(url);
|
|
|
|
|
}
|
2018-02-26 03:46:26 +00:00
|
|
|
sum.input += info.input;
|
|
|
|
|
sum.output += info.output;
|
|
|
|
|
sum.gzip += info.gzip;
|
2017-02-18 11:28:25 +00:00
|
|
|
});
|
2017-03-07 11:25:12 +00:00
|
|
|
if (failures.length) {
|
|
|
|
|
console.error("Benchmark failed:");
|
|
|
|
|
failures.forEach(function(url) {
|
|
|
|
|
console.error(url);
|
|
|
|
|
});
|
|
|
|
|
process.exit(1);
|
2018-02-26 03:46:26 +00:00
|
|
|
} else {
|
|
|
|
|
console.log();
|
|
|
|
|
console.log("Subtotal");
|
|
|
|
|
console.log();
|
|
|
|
|
console.log("Original:", sum.input, "bytes");
|
|
|
|
|
console.log("Uglified:", sum.output, "bytes");
|
|
|
|
|
console.log("GZipped: ", sum.gzip, "bytes");
|
2017-03-07 11:25:12 +00:00
|
|
|
}
|
2017-02-18 11:28:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
urls.forEach(function(url) {
|
2017-03-07 11:25:12 +00:00
|
|
|
results[url] = {
|
|
|
|
|
input: 0,
|
|
|
|
|
output: 0,
|
2017-07-08 17:44:59 +00:00
|
|
|
gzip: 0,
|
2017-03-07 11:25:12 +00:00
|
|
|
log: ""
|
|
|
|
|
};
|
2017-06-14 03:53:10 +00:00
|
|
|
fetch(url, function(err, res) {
|
|
|
|
|
if (err) throw err;
|
2020-04-14 02:13:42 +00:00
|
|
|
var uglifyjs = spawn(process.argv[0], args, { silent: true });
|
2017-03-07 11:25:12 +00:00
|
|
|
res.on("data", function(data) {
|
|
|
|
|
results[url].input += data.length;
|
|
|
|
|
}).pipe(uglifyjs.stdin);
|
2020-04-14 02:13:42 +00:00
|
|
|
var sha1 = createHash("sha1");
|
2017-03-07 11:25:12 +00:00
|
|
|
uglifyjs.stdout.on("data", function(data) {
|
|
|
|
|
results[url].output += data.length;
|
2017-07-11 18:55:57 +00:00
|
|
|
}).pipe(zlib.createGzip({
|
2017-07-08 17:44:59 +00:00
|
|
|
level: zlib.Z_BEST_COMPRESSION
|
|
|
|
|
})).on("data", function(data) {
|
|
|
|
|
results[url].gzip += data.length;
|
2020-04-14 02:13:42 +00:00
|
|
|
sha1.update(data);
|
|
|
|
|
}).on("end", function() {
|
|
|
|
|
results[url].sha1 = sha1.digest("hex");
|
2017-07-11 18:55:57 +00:00
|
|
|
done();
|
2017-07-08 17:44:59 +00:00
|
|
|
});
|
2017-02-18 11:28:25 +00:00
|
|
|
uglifyjs.stderr.setEncoding("utf8");
|
|
|
|
|
uglifyjs.stderr.on("data", function(data) {
|
2017-03-07 11:25:12 +00:00
|
|
|
results[url].log += data;
|
|
|
|
|
});
|
|
|
|
|
uglifyjs.on("exit", function(code) {
|
|
|
|
|
results[url].code = code;
|
|
|
|
|
done();
|
|
|
|
|
});
|
2017-02-18 11:28:25 +00:00
|
|
|
});
|
|
|
|
|
});
|