Cleanup perf.js.

Former-commit-id: 53285a24dcb27857a05b07aa7a6a8840026f8c42
This commit is contained in:
John-David Dalton
2012-07-02 17:59:09 -04:00
parent 0ae7fe9df5
commit 4352f18dd3

View File

@@ -46,6 +46,18 @@
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
/**
* Gets the Hz, i.e. operations per second, of `bench` adjusted for the
* margin of error.
*
* @private
* @param {Object} bench The benchmark object.
* @returns {Number} Returns the adjusted Hz.
*/
function getHz(bench) {
return 1 / (bench.stats.mean + bench.stats.moe);
}
/** /**
* Logs text to the console. * Logs text to the console.
* *
@@ -229,20 +241,24 @@
'onComplete': function() { 'onComplete': function() {
var formatNumber = Benchmark.formatNumber, var formatNumber = Benchmark.formatNumber,
fastest = this.filter('fastest'), fastest = this.filter('fastest'),
fastestHz = getHz(fastest[0]),
slowest = this.filter('slowest'), slowest = this.filter('slowest'),
lodashHz = 1 / (this[0].stats.mean + this[0].stats.moe), slowestHz = getHz(slowest[0]),
underscoreHz = 1 / (this[1].stats.mean + this[1].stats.moe); lodashHz = getHz(this[0]),
underscoreHz = getHz(this[1]);
if (fastest.length > 1) { if (fastest.length > 1) {
log('It\'s too close to call.'); log('It\'s too close to call.');
lodashHz = underscoreHz = Math.min(lodashHz, underscoreHz); lodashHz = underscoreHz = slowestHz;
} }
else { else {
var fastestHz = fastest[0] == this[0] ? lodashHz : underscoreHz, var percent = ((fastestHz / slowestHz) - 1) * 100;
slowestHz = slowest[0] == this[0] ? lodashHz : underscoreHz,
percent = ((fastestHz / slowestHz) - 1) * 100;
log(fastest[0].name + ' is ' + formatNumber(percent < 1 ? percent.toFixed(2) : Math.round(percent)) + '% faster.'); log(
fastest[0].name + ' is ' +
formatNumber(percent < 1 ? percent.toFixed(2) : Math.round(percent)) +
'% faster.'
);
} }
// add score adjusted for margin of error // add score adjusted for margin of error
score.lodash += lodashHz; score.lodash += lodashHz;