Comparing version 1.3.1 to 1.3.2
@@ -57,87 +57,93 @@ #!/usr/bin/env node | ||
exec('git rev-parse HEAD', function (err, stdout, stderr) { | ||
exec('git rev-parse --abbrev-ref 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.operationsPrSecond - otherResult.metadata.operationsPrSecond; | ||
var ratio = difference / otherResult.metadata.operationsPrSecond; | ||
numValidResults += 1; | ||
sumRatios += ratio; | ||
console.log(result.fullTitle, | ||
Math.round(result.metadata.operationsPrSecond), | ||
'/', | ||
Math.round(otherResult.metadata.operationsPrSecond), | ||
(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 ' + originalSha, 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 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.operationsPrSecond - otherResult.metadata.operationsPrSecond; | ||
var ratio = difference / otherResult.metadata.operationsPrSecond; | ||
numValidResults += 1; | ||
sumRatios += ratio; | ||
console.log(result.fullTitle, | ||
Math.round(result.metadata.operationsPrSecond), | ||
'/', | ||
Math.round(otherResult.metadata.operationsPrSecond), | ||
(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(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "chewbacca", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "A benchmark tool for Mocha test that will run the body of each test many times.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
15453
320
2