Skip to content

Commit a1fdd1c

Browse files
committed
merge from megawac
2 parents 22e89cb + 04dec37 commit a1fdd1c

File tree

2 files changed

+56
-42
lines changed

2 files changed

+56
-42
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"nodeunit": ">0.0.0",
4242
"nyc": "^2.1.0",
4343
"rsvp": "^3.0.18",
44+
"semver": "^4.3.6",
4445
"uglify-js": "~2.4.0",
4546
"xyz": "^0.5.0",
4647
"yargs": "~3.9.1"

perf/benchmark.js

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,49 @@
33
var _ = require("lodash");
44
var Benchmark = require("benchmark");
55
var exec = require("child_process").exec;
6+
var execSync = require("child_process").execSync;
67
var fs = require("fs");
78
var path = require("path");
89
var mkdirp = require("mkdirp");
910
var async = require("../");
1011
var suiteConfigs = require("./suites");
12+
var semver = require("semver");
1113

1214
var args = require("yargs")
13-
.usage("Usage: $0 [options] [tag1] [tag2]")
14-
.describe("g", "run only benchmarks whose names match this regex")
15-
.alias("g", "grep")
16-
.default("g", ".*")
17-
.describe("i", "skip benchmarks whose names match this regex")
18-
.alias("i", "reject")
19-
.default("i", "^$")
20-
.describe("l", "maximum running time per test (in seconds)")
21-
.alias("l", "limit")
22-
.default("l", 2)
23-
.help('h')
24-
.alias('h', 'help')
25-
.example('$0 0.9.2 0.9.0', 'Compare v0.9.2 with v0.9.0')
26-
.example('$0 0.9.2', 'Compare v0.9.2 with the current working version')
27-
.example('$0', 'Compare the latest tag with the current working version')
28-
.example('$0 -g each', 'only run the each(), eachLimit() and eachSeries() benchmarks')
29-
.example('')
30-
.argv;
15+
.usage("Usage: $0 [options] [tag1] [tag2]")
16+
.describe("g", "run only benchmarks whose names match this regex")
17+
.alias("g", "grep")
18+
.default("g", ".*")
19+
.describe("i", "skip benchmarks whose names match this regex")
20+
.alias("i", "reject")
21+
.default("i", "^$")
22+
.describe("l", "maximum running time per test (in seconds)")
23+
.alias("l", "limit")
24+
.default("l", 2)
25+
.help("h")
26+
.alias("h", "help")
27+
.example("$0 0.9.2 0.9.0", "Compare v0.9.2 with v0.9.0")
28+
.example("$0 0.9.2", "Compare v0.9.2 with the current working version")
29+
.example("$0", "Compare the latest tag with the current working version")
30+
.example("$0 -g each", "only run the each(), eachLimit() and " +
31+
"eachSeries() benchmarks")
32+
.example("")
33+
.argv;
3134

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

35-
var version0 = args._[0] || require("../package.json").version;
38+
function getLatestVersion() {
39+
var tags = execSync("git tag");
40+
var latest = _(tags).split("\n")
41+
.compact()
42+
.sort(semver.gt)
43+
.last();
44+
console.log("Latest tag is ", latest);
45+
return latest;
46+
}
47+
48+
var version0 = args._[0] || getLatestVersion();
3649
var version1 = args._[1] || "current";
3750
var versionNames = [version0, version1];
3851
var benchOptions = {defer: true, minSamples: 1, maxTime: +args.l};
@@ -52,12 +65,12 @@ async.eachSeries(versionNames, cloneVersion, function (err) {
5265
versions = versionNames.map(requireVersion);
5366

5467
var suites = suiteConfigs
55-
.map(setDefaultOptions)
56-
.reduce(handleMultipleArgs, [])
57-
.map(setName)
58-
.filter(matchesGrep)
59-
.filter(doesNotMatch)
60-
.map(createSuite);
68+
.map(setDefaultOptions)
69+
.reduce(handleMultipleArgs, [])
70+
.map(setName)
71+
.filter(matchesGrep)
72+
.filter(doesNotMatch)
73+
.map(createSuite);
6174

6275
async.eachSeries(suites, runSuite, function () {
6376
var totalTime0 = +totalTime[version0].toPrecision(3);
@@ -69,24 +82,24 @@ async.eachSeries(versionNames, cloneVersion, function (err) {
6982
if ( Math.abs((totalTime0 / totalTime1) - 1) < 0.01) {
7083
// if < 1% difference, we're likely within the margins of error
7184
console.log("Both versions are about equal " +
72-
"(" + totalTime0 + "ms total vs. " + totalTime1 + "ms total)");
85+
"(" + totalTime0 + "ms total vs. " + totalTime1 + "ms total)");
7386
} else if (totalTime0 < totalTime1) {
7487
console.log(version0 + " faster overall " +
75-
"(" + totalTime0 + "ms total vs. " + totalTime1 + "ms total)");
88+
"(" + totalTime0 + "ms total vs. " + totalTime1 + "ms total)");
7689
} else if (totalTime1 < totalTime0) {
7790
console.log(version1 + " faster overall " +
78-
"(" + totalTime1 + "ms total vs. " + totalTime0 + "ms total)");
91+
"(" + totalTime1 + "ms total vs. " + totalTime0 + "ms total)");
7992
}
8093

8194
if (wins0 > wins1) {
8295
console.log(version0 + " won more benchmarks " +
83-
"(" + wins0 + " vs. " + wins1 + ")");
96+
"(" + wins0 + " vs. " + wins1 + ")");
8497
} else if (wins1 > wins0) {
8598
console.log(version1 + " won more benchmarks " +
86-
"(" + wins1 + " vs. " + wins0 + ")");
99+
"(" + wins1 + " vs. " + wins0 + ")");
87100
} else {
88101
console.log("Both versions won the same number of benchmarks " +
89-
"(" + wins0 + " vs. " + wins1 + ")");
102+
"(" + wins0 + " vs. " + wins1 + ")");
90103
}
91104
});
92105
});
@@ -158,22 +171,22 @@ function createSuite(suiteConfig) {
158171

159172
return suite.on('cycle', function(event) {
160173
var mean = event.target.stats.mean * 1000;
161-
console.log(event.target + ", " + (+mean.toPrecision(3)) + "ms per run");
174+
console.log(event.target + ", " + mean.toPrecision(3) + "ms per run");
162175
var version = event.target.options.versionName;
163176
if (errored) return;
164177
totalTime[version] += mean;
165178
})
166179
.on('error', function (err) { console.error(err); })
167-
.on('complete', function() {
168-
if (!errored) {
169-
var fastest = this.filter('fastest');
170-
if (fastest.length === 2) {
171-
console.log("Tie");
172-
} else {
173-
var winner = fastest[0].options.versionName;
174-
console.log(winner + ' is faster');
175-
wins[winner]++;
176-
}
180+
.on('complete', function() {
181+
if (!errored) {
182+
var fastest = this.filter('fastest');
183+
if (fastest.length === 2) {
184+
console.log("Tie");
185+
} else {
186+
var winner = fastest[0].options.versionName;
187+
console.log(winner + ' is faster');
188+
wins[winner]++;
189+
}
177190
}
178191
console.log("--------------------------------------");
179192
});

0 commit comments

Comments
 (0)