mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +00:00
Make lib references more generic in perf.js.
Former-commit-id: 9984b8ac9f552d5a1051d738b57ff0b69b8d764a
This commit is contained in:
26
perf/perf.js
26
perf/perf.js
@@ -28,8 +28,8 @@
|
|||||||
/** Used to access the Firebug Lite panel (set by `run`) */
|
/** Used to access the Firebug Lite panel (set by `run`) */
|
||||||
var fbPanel;
|
var fbPanel;
|
||||||
|
|
||||||
/** Used to score Lo-Dash and Underscore performance */
|
/** Used to score performance */
|
||||||
var score = { 'lodash': 0, 'underscore': 0 };
|
var score = { 'a': 0, 'b': 0 };
|
||||||
|
|
||||||
/** Used to queue benchmark suites */
|
/** Used to queue benchmark suites */
|
||||||
var suites = [];
|
var suites = [];
|
||||||
@@ -38,10 +38,10 @@
|
|||||||
var ui = window.ui || {};
|
var ui = window.ui || {};
|
||||||
|
|
||||||
/** The Lo-Dash build basename */
|
/** The Lo-Dash build basename */
|
||||||
var buildName = basename(ui.buildPath || 'lodash.min', '.js');
|
var buildName = basename(ui.buildPath || 'lodash', '.js');
|
||||||
|
|
||||||
/** The other library basename */
|
/** The other library basename */
|
||||||
var otherName = basename(ui.otherPath || 'underscore-min', '.js');
|
var otherName = basename(ui.otherPath || 'underscore', '.js');
|
||||||
|
|
||||||
/** Add `console.log()` support for Narwhal and RingoJS */
|
/** Add `console.log()` support for Narwhal and RingoJS */
|
||||||
window.console || (window.console = { 'log': window.print });
|
window.console || (window.console = { 'log': window.print });
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the basename of the given `filePath`. If the file `extension` is passed
|
* Gets the basename of the given `filePath`. If the file `extension` is passed,
|
||||||
* it will be removed from the basename.
|
* it will be removed from the basename.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
@@ -124,12 +124,12 @@
|
|||||||
fastestHz = getHz(fastest[0]),
|
fastestHz = getHz(fastest[0]),
|
||||||
slowest = this.filter('slowest'),
|
slowest = this.filter('slowest'),
|
||||||
slowestHz = getHz(slowest[0]),
|
slowestHz = getHz(slowest[0]),
|
||||||
lodashHz = getHz(this[0]),
|
aHz = getHz(this[0]),
|
||||||
underscoreHz = getHz(this[1]);
|
bHz = 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 = slowestHz;
|
aHz = bHz = slowestHz;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var percent = ((fastestHz / slowestHz) - 1) * 100;
|
var percent = ((fastestHz / slowestHz) - 1) * 100;
|
||||||
@@ -141,8 +141,8 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
// add score adjusted for margin of error
|
// add score adjusted for margin of error
|
||||||
score.lodash += lodashHz;
|
score.a += aHz;
|
||||||
score.underscore += underscoreHz;
|
score.b += bHz;
|
||||||
|
|
||||||
// remove current suite from queue
|
// remove current suite from queue
|
||||||
suites.shift();
|
suites.shift();
|
||||||
@@ -152,14 +152,14 @@
|
|||||||
suites[0].run();
|
suites[0].run();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var fastestTotalHz = Math.max(score.lodash, score.underscore),
|
var fastestTotalHz = Math.max(score.a, score.b),
|
||||||
slowestTotalHz = Math.min(score.lodash, score.underscore),
|
slowestTotalHz = Math.min(score.a, score.b),
|
||||||
totalPercent = formatNumber(Math.round(((fastestTotalHz / slowestTotalHz) - 1) * 100)),
|
totalPercent = formatNumber(Math.round(((fastestTotalHz / slowestTotalHz) - 1) * 100)),
|
||||||
totalX = fastestTotalHz / slowestTotalHz,
|
totalX = fastestTotalHz / slowestTotalHz,
|
||||||
message = 'is ' + totalPercent + '% ' + (totalX == 1 ? '' : '(' + formatNumber(totalX.toFixed(2)) + 'x) ') + 'faster than';
|
message = 'is ' + totalPercent + '% ' + (totalX == 1 ? '' : '(' + formatNumber(totalX.toFixed(2)) + 'x) ') + 'faster than';
|
||||||
|
|
||||||
// report results
|
// report results
|
||||||
if (score.lodash >= score.underscore) {
|
if (score.a >= score.b) {
|
||||||
log('\n' + buildName + ' ' + message + ' ' + otherName + '.');
|
log('\n' + buildName + ' ' + message + ' ' + otherName + '.');
|
||||||
} else {
|
} else {
|
||||||
log('\n' + otherName + ' ' + message + ' ' + buildName + '.');
|
log('\n' + otherName + ' ' + message + ' ' + buildName + '.');
|
||||||
|
|||||||
Reference in New Issue
Block a user