mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 19:37:49 +00:00
Format numbers and scroll down results panel in perf.js.
Former-commit-id: 9f80b5534e3b46be7ad9c84ebb7e9ed5afdc35b8
This commit is contained in:
@@ -38,7 +38,7 @@
|
|||||||
script = document.createElement('script');
|
script = document.createElement('script');
|
||||||
|
|
||||||
document.getElementById('FirebugUI').style.height = '100%';
|
document.getElementById('FirebugUI').style.height = '100%';
|
||||||
script.src = 'perf.js';
|
script.src = 'perf.js?t=' + (+new Date);
|
||||||
sibling.parentNode.insertBefore(script, sibling);
|
sibling.parentNode.insertBefore(script, sibling);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
44
perf/perf.js
44
perf/perf.js
@@ -25,6 +25,11 @@
|
|||||||
_._ || _
|
_._ || _
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** Used to access the Firebug Lite panel */
|
||||||
|
var fbPanel = (fbPanel = window.document && document.getElementById('FirebugUI')) &&
|
||||||
|
(fbPanel = (fbPanel = fbPanel.contentWindow || fbPanel.contentDocument).document || fbPanel) &&
|
||||||
|
fbPanel.getElementById('fbPanel1');
|
||||||
|
|
||||||
/** Used to score Lo-Dash and Underscore performance */
|
/** Used to score Lo-Dash and Underscore performance */
|
||||||
var score = { 'lodash': 0, 'underscore': 0 };
|
var score = { 'lodash': 0, 'underscore': 0 };
|
||||||
|
|
||||||
@@ -41,6 +46,22 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs text to the console.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {String} text The text to log.
|
||||||
|
*/
|
||||||
|
function log(text) {
|
||||||
|
console.log(text);
|
||||||
|
if (fbPanel) {
|
||||||
|
// scroll down the Firebug Lite panel
|
||||||
|
fbPanel.scrollTop = fbPanel.scrollHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
lodash.extend(Benchmark.options, {
|
lodash.extend(Benchmark.options, {
|
||||||
'async': true,
|
'async': true,
|
||||||
'setup': function() {
|
'setup': function() {
|
||||||
@@ -83,27 +104,28 @@
|
|||||||
|
|
||||||
lodash.extend(Benchmark.Suite.options, {
|
lodash.extend(Benchmark.Suite.options, {
|
||||||
'onStart': function() {
|
'onStart': function() {
|
||||||
console.log('\n' + this.name + ':');
|
log('\n' + this.name + ':');
|
||||||
},
|
},
|
||||||
'onCycle': function(event) {
|
'onCycle': function(event) {
|
||||||
console.log(event.target + '');
|
log(event.target + '');
|
||||||
},
|
},
|
||||||
'onComplete': function() {
|
'onComplete': function() {
|
||||||
var fastest = this.filter('fastest'),
|
var formatNumber = Benchmark.formatNumber,
|
||||||
|
fastest = this.filter('fastest'),
|
||||||
slowest = this.filter('slowest'),
|
slowest = this.filter('slowest'),
|
||||||
lodashHz = 1 / (this[0].stats.mean + this[0].stats.moe),
|
lodashHz = 1 / (this[0].stats.mean + this[0].stats.moe),
|
||||||
underscoreHz = 1 / (this[1].stats.mean + this[1].stats.moe);
|
underscoreHz = 1 / (this[1].stats.mean + this[1].stats.moe);
|
||||||
|
|
||||||
if (fastest.length > 1) {
|
if (fastest.length > 1) {
|
||||||
console.log('It\'s too close to call.');
|
log('It\'s too close to call.');
|
||||||
lodashHz = underscoreHz = Math.min(lodashHz, underscoreHz);
|
lodashHz = underscoreHz = Math.min(lodashHz, underscoreHz);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var fastestHz = fastest[0] == this[0] ? lodashHz : underscoreHz,
|
var fastestHz = fastest[0] == this[0] ? lodashHz : underscoreHz,
|
||||||
slowestHz = slowest[0] == this[0] ? lodashHz : underscoreHz,
|
slowestHz = slowest[0] == this[0] ? lodashHz : underscoreHz,
|
||||||
percent = Math.round(((fastestHz / slowestHz) - 1) * 100);
|
percent = formatNumber(Math.round(((fastestHz / slowestHz) - 1) * 100));
|
||||||
|
|
||||||
console.log(fastest[0].name + ' is ' + percent + '% faster.');
|
log(fastest[0].name + ' is ' + percent + '% faster.');
|
||||||
}
|
}
|
||||||
// add score adjusted for margin of error
|
// add score adjusted for margin of error
|
||||||
score.lodash += lodashHz;
|
score.lodash += lodashHz;
|
||||||
@@ -119,15 +141,15 @@
|
|||||||
else {
|
else {
|
||||||
var fastestTotalHz = Math.max(score.lodash, score.underscore),
|
var fastestTotalHz = Math.max(score.lodash, score.underscore),
|
||||||
slowestTotalHz = Math.min(score.lodash, score.underscore),
|
slowestTotalHz = Math.min(score.lodash, score.underscore),
|
||||||
totalPercent = Math.round(((fastestTotalHz / slowestTotalHz) - 1) * 100),
|
totalPercent = formatNumber(Math.round(((fastestTotalHz / slowestTotalHz) - 1) * 100)),
|
||||||
totalX = (fastestTotalHz / slowestTotalHz).toFixed(2),
|
totalX = formatNumber((fastestTotalHz / slowestTotalHz).toFixed(2)),
|
||||||
message = ' is ' + totalPercent + '% (' + totalX + 'x) faster than ';
|
message = ' is ' + totalPercent + '% (' + totalX + 'x) faster than ';
|
||||||
|
|
||||||
// report results
|
// report results
|
||||||
if (score.lodash >= score.underscore) {
|
if (score.lodash >= score.underscore) {
|
||||||
console.log('\nLo-Dash' + message + 'Underscore.');
|
log('\nLo-Dash' + message + 'Underscore.');
|
||||||
} else {
|
} else {
|
||||||
console.log('\nUnderscore' + message + 'Lo-Dash.');
|
log('\nUnderscore' + message + 'Lo-Dash.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -396,7 +418,7 @@
|
|||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
if (Benchmark.platform + '') {
|
if (Benchmark.platform + '') {
|
||||||
console.log(Benchmark.platform + '');
|
log(Benchmark.platform + '');
|
||||||
}
|
}
|
||||||
// start suites
|
// start suites
|
||||||
suites[0].run();
|
suites[0].run();
|
||||||
|
|||||||
Reference in New Issue
Block a user