Comparing version 1.7.1 to 1.8.0
#!/usr/bin/env node | ||
var childProcess = require('child_process'); | ||
var async = require('async'); | ||
var passError = require('passerror'); | ||
var Promise = require('bluebird'); | ||
var promisifiedExec = Promise.promisify(require('child_process').exec); | ||
var argv = require('minimist')(process.argv.slice(2), { | ||
@@ -33,3 +32,3 @@ '--': true | ||
function exec(commandLine, quiet, cb) { | ||
function exec(commandLine, quiet) { | ||
if (typeof quiet === 'function') { | ||
@@ -40,7 +39,7 @@ cb = quiet; | ||
console.log(commandLine); | ||
childProcess.exec(commandLine, function (err, stdout, stderr) { | ||
return promisifiedExec(commandLine).spread(function (stdout, stderr) { | ||
if (stderr.length > 0 && !quiet) { | ||
console.log(stderr.toString('utf-8')); | ||
} | ||
cb(err, stdout, stderr); | ||
return [stdout, stderr]; | ||
}); | ||
@@ -50,103 +49,90 @@ } | ||
var dirtyWorkingTree = false; | ||
exec('git diff-index --quiet HEAD', function (err, stdout, stderr) { | ||
if (err) { | ||
if (err.code > 0) { | ||
dirtyWorkingTree = true; | ||
} else { | ||
throw err; | ||
var originalSha; | ||
var originalRef; | ||
function benchmarkRef(ref) { | ||
return Promise.resolve().then(function () { | ||
if (ref !== 'working dir') { | ||
if (dirtyWorkingTree) { | ||
return exec('git stash').then(function () { | ||
return exec('git checkout ' + ref.replace(/^HEAD/, originalSha)); | ||
}); | ||
} else { | ||
return exec('git checkout ' + ref.replace(/^HEAD/, originalSha), true); | ||
} | ||
} | ||
}).then(function () { | ||
return exec('./node_modules/.bin/mocha ' + | ||
'--no-timeouts ' + | ||
'--ui chewbacca/mocha-benchmark-ui ' + | ||
'--reporter chewbacca/mocha-benchmark-reporter ' + | ||
mochaArgs); | ||
}).delay(2000).then(function () { | ||
return exec('./node_modules/.bin/mocha ' + | ||
'--no-timeouts ' + | ||
'--ui chewbacca/mocha-benchmark-ui ' + | ||
'--reporter chewbacca/mocha-benchmark-reporter ' + | ||
mochaArgs); | ||
}).spread(function (stdout) { | ||
var result = JSON.parse(stdout.toString('utf-8')); | ||
result.ref = ref; | ||
return result; | ||
}); | ||
} | ||
exec('git diff-index --quiet HEAD').caught(function (err) { | ||
if (err.code > 0) { | ||
dirtyWorkingTree = true; | ||
} else { | ||
throw err; | ||
} | ||
exec('git rev-parse --abbrev-ref HEAD', function (err, stdout, stderr) { | ||
if (err) { | ||
throw err; | ||
}).then(function () { | ||
return exec('git rev-parse --abbrev-ref HEAD'); | ||
}).spread(function (stdout) { | ||
originalRef = stdout.toString('utf-8').replace(/\n/, ''); | ||
return exec('git rev-parse HEAD'); | ||
}).spread(function (stdout) { | ||
originalSha = stdout.toString('utf-8').replace(/\n/, ''); | ||
return refs; | ||
}).map(benchmarkRef, { concurrency: 1 }).then(function (results) { | ||
var numValidResults = 0; | ||
var sumRatios = 0; | ||
console.log(results.map(function (result) { | ||
return result.ref; | ||
}).join(' vs. ')); | ||
results[0].passes.forEach(function (result, i) { | ||
var otherResult = results[1].passes[i]; | ||
if (otherResult.fullTitle === result.fullTitle) { | ||
var difference = result.metadata.operationsPrSecond - otherResult.metadata.operationsPrSecond; | ||
var ratio = difference / otherResult.metadata.operationsPrSecond; | ||
numValidResults += 1; | ||
sumRatios += ratio; | ||
console.log(result.fullTitle, | ||
Math.round(otherResult.metadata.operationsPrSecond), | ||
'vs.', | ||
Math.round(result.metadata.operationsPrSecond), | ||
'ops', | ||
(100 * Math.abs(ratio)).toFixed(2) + '%', | ||
ratio < 0 ? 'slower' : 'faster' | ||
); | ||
} | ||
var originalRef = stdout.toString('utf-8').replace(/\n/, ''); | ||
exec('git rev-parse HEAD', function (err, stdout, stderr) { | ||
if (err) { | ||
throw err; | ||
} | ||
var originalSha = stdout.toString('utf-8').replace(/\n/, ''); | ||
async.eachLimit(refs, 1, function (ref, cb) { | ||
if (ref === 'working dir') { | ||
proceedToRunBenchmark(); | ||
} else { | ||
if (dirtyWorkingTree) { | ||
exec('git stash', passError(cb, function () { | ||
exec('git checkout ' + ref.replace(/^HEAD/, originalSha), true, passError(cb, proceedToRunBenchmark)); | ||
})); | ||
} else { | ||
exec('git checkout ' + ref.replace(/^HEAD/, originalSha), true, passError(cb, proceedToRunBenchmark)); | ||
} | ||
} | ||
function proceedToRunBenchmark() { | ||
exec('./node_modules/.bin/mocha ' + | ||
'--no-timeouts ' + | ||
'--ui chewbacca/mocha-benchmark-ui ' + | ||
'--reporter chewbacca/mocha-benchmark-reporter ' + | ||
mochaArgs, passError(cb, function (stdout, stderr) { | ||
var result = JSON.parse(stdout.toString('utf-8')); | ||
result.ref = ref; | ||
results.push(result); | ||
cb(); | ||
})); | ||
} | ||
}, function (err) { | ||
if (err) { | ||
throw err; | ||
} | ||
var numValidResults = 0; | ||
var sumRatios = 0; | ||
console.log(results.map(function (result) { | ||
return result.ref; | ||
}).join(' vs. ')); | ||
results[0].passes.forEach(function (result, i) { | ||
var otherResult = results[1].passes[i]; | ||
if (otherResult.fullTitle === result.fullTitle) { | ||
var difference = result.metadata.averageDurationInNanoseconds - otherResult.metadata.averageDurationInNanoseconds; | ||
var ratio = difference / otherResult.metadata.averageDurationInNanoseconds; | ||
numValidResults += 1; | ||
sumRatios += ratio; | ||
console.log(result.fullTitle, | ||
Math.round(otherResult.metadata.operationsPrSecond), | ||
'vs.', | ||
Math.round(result.metadata.operationsPrSecond), | ||
'ops', | ||
(100 * Math.abs(ratio)).toFixed(2) + '%', | ||
ratio < 0 ? 'slower' : 'faster' | ||
); | ||
} | ||
}); | ||
var avg = sumRatios / numValidResults; | ||
console.log(results[0].ref, | ||
'is', | ||
(100 * Math.abs(avg)).toFixed(2) + '%', | ||
avg < 0 ? 'slower' : 'faster', | ||
'than', | ||
results[1].ref, | ||
'on average'); | ||
exec('git checkout ' + (originalRef === 'HEAD' ? originalSha : originalRef), true, function (err) { | ||
function onFinish() { | ||
if (typeof argv.threshold === 'number' && argv.threshold <= -avg * 100) { | ||
console.log('Performance regression higher than threshold'); | ||
process.exit(1); | ||
} | ||
} | ||
if (err) { | ||
throw err; | ||
} | ||
if (dirtyWorkingTree) { | ||
exec('git stash pop', function (err) { | ||
if (err) { | ||
throw err; | ||
} | ||
onFinish(); | ||
}); | ||
} else { | ||
onFinish(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
var avg = sumRatios / numValidResults; | ||
console.log(results[0].ref, | ||
'is', | ||
(100 * Math.abs(avg)).toFixed(2) + '%', | ||
avg < 0 ? 'slower' : 'faster', | ||
'than', | ||
results[1].ref, | ||
'on average'); | ||
return exec('git checkout ' + (originalRef === 'HEAD' ? originalSha : originalRef), true); | ||
}).then(function () { | ||
if (dirtyWorkingTree) { | ||
return exec('git stash pop'); | ||
} | ||
}).then(function () { | ||
if (typeof argv.threshold === 'number' && argv.threshold <= -avg * 100) { | ||
console.log('Performance regression higher than threshold'); | ||
process.exit(1); | ||
} | ||
}); |
var Mocha = require('mocha'); | ||
var Suite = require('mocha/lib/suite'); | ||
var Test = require('mocha/lib/test'); | ||
var Promise = require('rsvp').Promise; | ||
var escapeRe = require('escape-string-regexp'); | ||
@@ -6,0 +5,0 @@ |
{ | ||
"name": "chewbacca", | ||
"version": "1.7.1", | ||
"version": "1.8.0", | ||
"description": "A benchmark tool for Mocha test that will run the body of each test many times.", | ||
@@ -15,6 +15,6 @@ "scripts": { | ||
"async": "1.4.2", | ||
"bluebird": "2.10.0", | ||
"escape-string-regexp": "1.0.3", | ||
"minimist": "1.2.0", | ||
"passerror": "1.1.0", | ||
"rsvp": "3.1.0" | ||
"passerror": "1.1.0" | ||
}, | ||
@@ -21,0 +21,0 @@ "peerDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14698
319
+ Addedbluebird@2.10.0
+ Addedbluebird@2.10.0(transitive)
- Removedrsvp@3.1.0
- Removedrsvp@3.1.0(transitive)