Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chewbacca

Package Overview
Dependencies
Maintainers
3
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chewbacca - npm Package Compare versions

Comparing version 1.3.1 to 1.3.2

170

bin/chewbacca.js

@@ -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": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc