summaryrefslogtreecommitdiff
path: root/perf
diff options
context:
space:
mode:
authorGraeme Yeates <yeatesgraeme@gmail.com>2015-07-01 15:07:27 -0400
committerGraeme Yeates <yeatesgraeme@gmail.com>2015-07-01 15:07:27 -0400
commit04dec370886cbd11845bd30559465ca29bda14ef (patch)
tree64256cc435e437c95daf531c74393c483eba1521 /perf
parent713cda968b801550271ba099d1cbba63b7edb01b (diff)
downloadasync-04dec370886cbd11845bd30559465ca29bda14ef.tar.gz
Fix tag detection methodology
Diffstat (limited to 'perf')
-rwxr-xr-xperf/benchmark.js40
1 files changed, 26 insertions, 14 deletions
diff --git a/perf/benchmark.js b/perf/benchmark.js
index e943f10..b077c3e 100755
--- a/perf/benchmark.js
+++ b/perf/benchmark.js
@@ -3,11 +3,13 @@
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]")
@@ -20,19 +22,29 @@ var args = require("yargs")
.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('')
+ .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};
@@ -67,7 +79,7 @@ async.eachSeries(versionNames, cloneVersion, function (err) {
var wins1 = wins[version1];
if ( Math.abs((totalTime0 / totalTime1) - 1) < 0.01) {
- // if < 1% difference, we're likely within the margins of error
+ // 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)");
} else if (totalTime0 < totalTime1) {
@@ -156,22 +168,22 @@ function createSuite(suiteConfig) {
addBench(versions[1], versionNames[1]);
- return suite.on('cycle', function(event) {
+ return suite.on("cycle", function(event) {
var mean = event.target.stats.mean * 1000;
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() {
+ .on("error", function (err) { console.error(err); })
+ .on("complete", function() {
if (!errored) {
- var fastest = this.filter('fastest');
+ var fastest = this.filter("fastest");
if (fastest.length === 2) {
console.log("Tie");
} else {
var winner = fastest[0].options.versionName;
- console.log(winner + ' is faster');
+ console.log(winner + " is faster");
wins[winner]++;
}
}