Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve benchmarks accuracy #148

Merged
merged 10 commits into from Nov 27, 2016
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 40 additions & 8 deletions scripts/benchmark.js
Expand Up @@ -17,6 +17,8 @@ const compile = require("google-closure-compiler-js").compile;

let packagename, filename;

const NUM_TEST_RUNS = 3;

const script = new Command("benchmark.js")
.option("-o, --offline", "Only install package if not present; package not removed after testing")
.usage("[options] <package> [file]")
Expand All @@ -35,7 +37,7 @@ if (!packagename) {
const pathToScripts = __dirname;

const table = new Table({
head: ["", "raw", "raw win", "gzip", "gzip win", "parse time", "run"],
head: ["", "raw", "raw win", "gzip", "gzip win", "parse time", "run time (average)"],
chars: {
top: "",
"top-mid": "" ,
Expand Down Expand Up @@ -100,7 +102,8 @@ function checkFile() {
}

function test(name, callback) {
console.log("testing", name);

console.log('testing', name);

const start = Date.now();
const result = callback(code);
Expand All @@ -116,23 +119,54 @@ function test(name, callback) {
const parseEnd = Date.now();
const parseNow = parseEnd - parseStart;

const runTimes = [run];

for (var i = 1; i < NUM_TEST_RUNS; i++) {
const start = Date.now();
const result = callback(code);
runTimes.push(Date.now() - start);
}

const totalTime = runTimes.reduce((a, b) => a + b, 0);
const average = parseInt(totalTime / runTimes.length, 10);

results.push({
name: name,
raw: result.length,
gzip: gzipped.length,
parse: parseNow,
run: run,
run: average,
});
}

function testFile() {
code = fs.readFileSync(filename, "utf8");
gzippedCode = zlib.gzipSync(code);

test("babili", function (code) {
test("babili (best speed)", function (code) {
return babel.transform(code, {
sourceType: "script",
presets: [require("../packages/babel-preset-babili")],
presets: [
[require("../packages/babel-preset-babili"), {
simplify: {
multiPass: false
}
}]
],
comments: false,
}).code;
});

test("babili (best size)", function (code) {
return babel.transform(code, {
sourceType: "script",
presets: [
[require("../packages/babel-preset-babili"), {
simplify: {
multiPass: true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@boopathi this doesn't seem to show any difference in any of the files I'm testing...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no multipass option implemented in simplify.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You implemented it here - in this commit - 827a835#diff-05684bffcab704dd5d3842adbf921357 and your latest changes don't seem to have this one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I'm an idiot, was thinking that we already added it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still doesn't seem to work though. Am I missing something else? Should I change anything in options-manager?

}
}]
],
comments: false,
}).code;
});
Expand Down Expand Up @@ -161,9 +195,7 @@ function testFile() {
}

function processResults() {
results = results.sort(function (a, b) {
return a.gzip > b.gzip;
});
results = results.sort((a, b) => a.gzip > b.gzip);

results.forEach(function (result, i) {
let row = [
Expand Down