Skip to content

Commit

Permalink
merge from megawac
Browse files Browse the repository at this point in the history
  • Loading branch information
aearly committed Oct 25, 2015
2 parents 22e89cb + 04dec37 commit a1fdd1c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 42 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"nodeunit": ">0.0.0",
"nyc": "^2.1.0",
"rsvp": "^3.0.18",
"semver": "^4.3.6",
"uglify-js": "~2.4.0",
"xyz": "^0.5.0",
"yargs": "~3.9.1"
Expand Down
97 changes: 55 additions & 42 deletions perf/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,49 @@
var _ = require("lodash");
var Benchmark = require("benchmark");
var exec = require("child_process").exec;
var execSync = require("child_process").execSync;
var fs = require("fs");
var path = require("path");
var mkdirp = require("mkdirp");
var async = require("../");
var suiteConfigs = require("./suites");
var semver = require("semver");

var args = require("yargs")
.usage("Usage: $0 [options] [tag1] [tag2]")
.describe("g", "run only benchmarks whose names match this regex")
.alias("g", "grep")
.default("g", ".*")
.describe("i", "skip benchmarks whose names match this regex")
.alias("i", "reject")
.default("i", "^$")
.describe("l", "maximum running time per test (in seconds)")
.alias("l", "limit")
.default("l", 2)
.help('h')
.alias('h', 'help')
.example('$0 0.9.2 0.9.0', 'Compare v0.9.2 with v0.9.0')
.example('$0 0.9.2', 'Compare v0.9.2 with the current working version')
.example('$0', 'Compare the latest tag with the current working version')
.example('$0 -g each', 'only run the each(), eachLimit() and eachSeries() benchmarks')
.example('')
.argv;
.usage("Usage: $0 [options] [tag1] [tag2]")
.describe("g", "run only benchmarks whose names match this regex")
.alias("g", "grep")
.default("g", ".*")
.describe("i", "skip benchmarks whose names match this regex")
.alias("i", "reject")
.default("i", "^$")
.describe("l", "maximum running time per test (in seconds)")
.alias("l", "limit")
.default("l", 2)
.help("h")
.alias("h", "help")
.example("$0 0.9.2 0.9.0", "Compare v0.9.2 with v0.9.0")
.example("$0 0.9.2", "Compare v0.9.2 with the current working version")
.example("$0", "Compare the latest tag with the current working version")
.example("$0 -g each", "only run the each(), eachLimit() and " +
"eachSeries() benchmarks")
.example("")
.argv;

var grep = new RegExp(args.g, "i");
var reject = new RegExp(args.i, "i");

var version0 = args._[0] || require("../package.json").version;
function getLatestVersion() {
var tags = execSync("git tag");
var latest = _(tags).split("\n")
.compact()
.sort(semver.gt)
.last();
console.log("Latest tag is ", latest);
return latest;
}

var version0 = args._[0] || getLatestVersion();
var version1 = args._[1] || "current";
var versionNames = [version0, version1];
var benchOptions = {defer: true, minSamples: 1, maxTime: +args.l};
Expand All @@ -52,12 +65,12 @@ async.eachSeries(versionNames, cloneVersion, function (err) {
versions = versionNames.map(requireVersion);

var suites = suiteConfigs
.map(setDefaultOptions)
.reduce(handleMultipleArgs, [])
.map(setName)
.filter(matchesGrep)
.filter(doesNotMatch)
.map(createSuite);
.map(setDefaultOptions)
.reduce(handleMultipleArgs, [])
.map(setName)
.filter(matchesGrep)
.filter(doesNotMatch)
.map(createSuite);

async.eachSeries(suites, runSuite, function () {
var totalTime0 = +totalTime[version0].toPrecision(3);
Expand All @@ -69,24 +82,24 @@ async.eachSeries(versionNames, cloneVersion, function (err) {
if ( Math.abs((totalTime0 / totalTime1) - 1) < 0.01) {
// if < 1% difference, we're likely within the margins of error
console.log("Both versions are about equal " +
"(" + totalTime0 + "ms total vs. " + totalTime1 + "ms total)");
"(" + totalTime0 + "ms total vs. " + totalTime1 + "ms total)");
} else if (totalTime0 < totalTime1) {
console.log(version0 + " faster overall " +
"(" + totalTime0 + "ms total vs. " + totalTime1 + "ms total)");
"(" + totalTime0 + "ms total vs. " + totalTime1 + "ms total)");
} else if (totalTime1 < totalTime0) {
console.log(version1 + " faster overall " +
"(" + totalTime1 + "ms total vs. " + totalTime0 + "ms total)");
"(" + totalTime1 + "ms total vs. " + totalTime0 + "ms total)");
}

if (wins0 > wins1) {
console.log(version0 + " won more benchmarks " +
"(" + wins0 + " vs. " + wins1 + ")");
"(" + wins0 + " vs. " + wins1 + ")");
} else if (wins1 > wins0) {
console.log(version1 + " won more benchmarks " +
"(" + wins1 + " vs. " + wins0 + ")");
"(" + wins1 + " vs. " + wins0 + ")");
} else {
console.log("Both versions won the same number of benchmarks " +
"(" + wins0 + " vs. " + wins1 + ")");
"(" + wins0 + " vs. " + wins1 + ")");
}
});
});
Expand Down Expand Up @@ -158,22 +171,22 @@ function createSuite(suiteConfig) {

return suite.on('cycle', function(event) {
var mean = event.target.stats.mean * 1000;
console.log(event.target + ", " + (+mean.toPrecision(3)) + "ms per run");
console.log(event.target + ", " + mean.toPrecision(3) + "ms per run");
var version = event.target.options.versionName;
if (errored) return;
totalTime[version] += mean;
})
.on('error', function (err) { console.error(err); })
.on('complete', function() {
if (!errored) {
var fastest = this.filter('fastest');
if (fastest.length === 2) {
console.log("Tie");
} else {
var winner = fastest[0].options.versionName;
console.log(winner + ' is faster');
wins[winner]++;
}
.on('complete', function() {
if (!errored) {
var fastest = this.filter('fastest');
if (fastest.length === 2) {
console.log("Tie");
} else {
var winner = fastest[0].options.versionName;
console.log(winner + ' is faster');
wins[winner]++;
}
}
console.log("--------------------------------------");
});
Expand Down

0 comments on commit a1fdd1c

Please sign in to comment.