perf.js (lodash-3.0.0) | : | perf.js (lodash-4.0.0) | ||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
/** Method and object shortcuts. */ | /** Method and object shortcuts. */ | |||
var phantom = root.phantom, | var phantom = root.phantom, | |||
amd = root.define && define.amd, | amd = root.define && define.amd, | |||
argv = root.process && process.argv, | argv = root.process && process.argv, | |||
document = !phantom && root.document, | document = !phantom && root.document, | |||
noop = function() {}, | noop = function() {}, | |||
params = root.arguments, | params = root.arguments, | |||
system = root.system; | system = root.system; | |||
/** Add `console.log()` support for Narwhal, Rhino, and RingoJS. */ | /** Add `console.log()` support for Rhino and RingoJS. */ | |||
var console = root.console || (root.console = { 'log': root.print }); | var console = root.console || (root.console = { 'log': root.print }); | |||
/** The file path of the lodash file to test. */ | /** The file path of the lodash file to test. */ | |||
var filePath = (function() { | var filePath = (function() { | |||
var min = 0, | var min = 0, | |||
result = []; | result = []; | |||
if (phantom) { | if (phantom) { | |||
result = params = phantom.args; | result = params = phantom.args; | |||
} else if (system) { | } else if (system) { | |||
min = 1; | min = 1; | |||
result = params = system.args; | result = params = system.args; | |||
} else if (argv) { | } else if (argv) { | |||
min = 2; | min = 2; | |||
result = params = argv; | result = params = argv; | |||
} else if (params) { | } else if (params) { | |||
result = params; | result = params; | |||
} | } | |||
var last = result[result.length - 1]; | var last = result[result.length - 1]; | |||
result = (result.length > min && !/perf(?:\.js)?$/.test(last)) ? last : '../ lodash.src.js'; | result = (result.length > min && !/perf(?:\.js)?$/.test(last)) ? last : '../ lodash.js'; | |||
if (!amd) { | if (!amd) { | |||
try { | try { | |||
result = require('fs').realpathSync(result); | result = require('fs').realpathSync(result); | |||
} catch(e) {} | } catch(e) {} | |||
try { | try { | |||
result = require.resolve(result); | result = require.resolve(result); | |||
} catch(e) {} | } catch(e) {} | |||
} | } | |||
skipping to change at line 91 | skipping to change at line 91 | |||
/** Used to queue benchmark suites. */ | /** Used to queue benchmark suites. */ | |||
var suites = []; | var suites = []; | |||
/** Used to resolve a value's internal [[Class]]. */ | /** Used to resolve a value's internal [[Class]]. */ | |||
var toString = Object.prototype.toString; | var toString = Object.prototype.toString; | |||
/** Detect if in a browser environment. */ | /** Detect if in a browser environment. */ | |||
var isBrowser = isHostType(root, 'document') && isHostType(root, 'navigator'); | var isBrowser = isHostType(root, 'document') && isHostType(root, 'navigator'); | |||
/** Detect if in a Java environment. */ | ||||
var isJava = !isBrowser && /Java/.test(toString.call(root.java)); | ||||
/** Use a single "load" function. */ | /** Use a single "load" function. */ | |||
var load = (typeof require == 'function' && !amd) | var load = (typeof require == 'function' && !amd) | |||
? require | ? require | |||
: (isJava && root.load) || noop; | : noop; | |||
/** Load lodash. */ | /** Load lodash. */ | |||
var lodash = root.lodash || (root.lodash = ( | var lodash = root.lodash || (root.lodash = ( | |||
lodash = load(filePath) || root._, | lodash = load(filePath) || root._, | |||
lodash = lodash._ || lodash, | lodash = lodash._ || lodash, | |||
(lodash.runInContext ? lodash.runInContext(root) : lodash), | (lodash.runInContext ? lodash.runInContext(root) : lodash), | |||
lodash.noConflict() | lodash.noConflict() | |||
)); | )); | |||
/** Load Underscore. */ | ||||
var _ = root.underscore || (root.underscore = ( | ||||
_ = load('../vendor/underscore/underscore.js') || root._, | ||||
_._ || _ | ||||
)); | ||||
/** Load Benchmark.js. */ | /** Load Benchmark.js. */ | |||
var Benchmark = root.Benchmark || (root.Benchmark = ( | var Benchmark = root.Benchmark || (root.Benchmark = ( | |||
Benchmark = load('../vendor/benchmark.js/benchmark.js') || root.Benchmark, | Benchmark = load('../vendor/benchmark.js/benchmark.js') || root.Benchmark, | |||
Benchmark = Benchmark.Benchmark || Benchmark, | Benchmark = Benchmark.Benchmark || Benchmark, | |||
Benchmark.runInContext(lodash.extend({}, root, { '_': lodash })) | Benchmark.runInContext(lodash.extend({}, root, { '_': lodash })) | |||
)); | )); | |||
/** Load Underscore. */ | ||||
var _ = root._ || (root._ = ( | ||||
_ = load('../vendor/underscore/underscore.js') || root._, | ||||
_._ || _ | ||||
)); | ||||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
/** | /** | |||
* Gets the basename of the given `filePath`. If the file `extension` is passe d, | * Gets the basename of the given `filePath`. If the file `extension` is passe d, | |||
* it will be removed from the basename. | * it will be removed from the basename. | |||
* | * | |||
* @private | * @private | |||
* @param {string} path The file path to inspect. | * @param {string} path The file path to inspect. | |||
* @param {string} extension The extension to remove. | * @param {string} extension The extension to remove. | |||
* @returns {string} Returns the basename. | * @returns {string} Returns the basename. | |||
skipping to change at line 208 | skipping to change at line 205 | |||
* Runs all benchmark suites. | * Runs all benchmark suites. | |||
* | * | |||
* @private (@public in the browser) | * @private (@public in the browser) | |||
*/ | */ | |||
function run() { | function run() { | |||
fbPanel = (fbPanel = root.document && document.getElementById('FirebugUI')) && | fbPanel = (fbPanel = root.document && document.getElementById('FirebugUI')) && | |||
(fbPanel = (fbPanel = fbPanel.contentWindow || fbPanel.contentDocument).do cument || fbPanel) && | (fbPanel = (fbPanel = fbPanel.contentWindow || fbPanel.contentDocument).do cument || fbPanel) && | |||
fbPanel.getElementById('fbPanel1'); | fbPanel.getElementById('fbPanel1'); | |||
log('\nSit back and relax, this may take a while.'); | log('\nSit back and relax, this may take a while.'); | |||
suites[0].run({ 'async': !isJava }); | suites[0].run({ 'async': true }); | |||
} | } | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
lodash.extend(Benchmark.Suite.options, { | lodash.extend(Benchmark.Suite.options, { | |||
'onStart': function() { | 'onStart': function() { | |||
log('\n' + this.name + ':'); | log('\n' + this.name + ':'); | |||
}, | }, | |||
'onCycle': function(event) { | 'onCycle': function(event) { | |||
log(event.target); | log(event.target); | |||
skipping to change at line 261 | skipping to change at line 258 | |||
} | } | |||
// Add score adjusted for margin of error. | // Add score adjusted for margin of error. | |||
score.a.push(aHz); | score.a.push(aHz); | |||
score.b.push(bHz); | score.b.push(bHz); | |||
} | } | |||
// Remove current suite from queue. | // Remove current suite from queue. | |||
suites.shift(); | suites.shift(); | |||
if (suites.length) { | if (suites.length) { | |||
// Run next suite. | // Run next suite. | |||
suites[0].run({ 'async': !isJava }); | suites[0].run({ 'async': true }); | |||
} | } | |||
else { | else { | |||
var aMeanHz = getGeometricMean(score.a), | var aMeanHz = getGeometricMean(score.a), | |||
bMeanHz = getGeometricMean(score.b), | bMeanHz = getGeometricMean(score.b), | |||
fastestMeanHz = Math.max(aMeanHz, bMeanHz), | fastestMeanHz = Math.max(aMeanHz, bMeanHz), | |||
slowestMeanHz = Math.min(aMeanHz, bMeanHz), | slowestMeanHz = Math.min(aMeanHz, bMeanHz), | |||
xFaster = fastestMeanHz / slowestMeanHz, | xFaster = fastestMeanHz / slowestMeanHz, | |||
percentFaster = formatNumber(Math.round((xFaster - 1) * 100)), | percentFaster = formatNumber(Math.round((xFaster - 1) * 100)), | |||
message = 'is ' + percentFaster + '% ' + (xFaster == 1 ? '' : '(' + formatNumber(xFaster.toFixed(2)) + 'x) ') + 'faster than'; | message = 'is ' + percentFaster + '% ' + (xFaster == 1 ? '' : '(' + formatNumber(xFaster.toFixed(2)) + 'x) ') + 'faster than'; | |||
skipping to change at line 287 | skipping to change at line 284 | |||
} | } | |||
} | } | |||
} | } | |||
}); | }); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
lodash.extend(Benchmark.options, { | lodash.extend(Benchmark.options, { | |||
'async': true, | 'async': true, | |||
'setup': '\ | 'setup': '\ | |||
var _ = global._,\ | var _ = global.underscore,\ | |||
lodash = global.lodash,\ | lodash = global.lodash,\ | |||
belt = this.name == buildName ? lodash : _;\ | belt = this.name == buildName ? lodash : _;\ | |||
\ | \ | |||
var date = new Date,\ | var date = new Date,\ | |||
limit = 50,\ | limit = 50,\ | |||
regexp = /x/,\ | regexp = /x/,\ | |||
object = {},\ | object = {},\ | |||
objects = Array(limit),\ | objects = Array(limit),\ | |||
numbers = Array(limit),\ | numbers = Array(limit),\ | |||
fourNumbers = [5, 25, 10, 30],\ | fourNumbers = [5, 25, 10, 30],\ | |||
skipping to change at line 309 | skipping to change at line 306 | |||
nestedObjects = [{}, [{}], [{}, [[{}]]]],\ | nestedObjects = [{}, [{}], [{}, [[{}]]]],\ | |||
twoNumbers = [12, 23];\ | twoNumbers = [12, 23];\ | |||
\ | \ | |||
for (var index = 0; index < limit; index++) {\ | for (var index = 0; index < limit; index++) {\ | |||
numbers[index] = index;\ | numbers[index] = index;\ | |||
object["key" + index] = index;\ | object["key" + index] = index;\ | |||
objects[index] = { "num": index };\ | objects[index] = { "num": index };\ | |||
}\ | }\ | |||
var strNumbers = numbers + "";\ | var strNumbers = numbers + "";\ | |||
\ | \ | |||
if (typeof assign != "undefined") {\ | ||||
var _assign = _.assign || _.extend,\ | ||||
lodashAssign = lodash.assign;\ | ||||
}\ | ||||
if (typeof bind != "undefined") {\ | if (typeof bind != "undefined") {\ | |||
var thisArg = { "name": "fred" };\ | var thisArg = { "name": "fred" };\ | |||
\ | \ | |||
var func = function(greeting, punctuation) {\ | var func = function(greeting, punctuation) {\ | |||
return (greeting || "hi") + " " + this.name + (punctuation || ".");\ | return (greeting || "hi") + " " + this.name + (punctuation || ".");\ | |||
};\ | };\ | |||
\ | \ | |||
var _boundNormal = _.bind(func, thisArg),\ | var _boundNormal = _.bind(func, thisArg),\ | |||
_boundMultiple = _boundNormal,\ | _boundMultiple = _boundNormal,\ | |||
_boundPartial = _.bind(func, thisArg, "hi");\ | _boundPartial = _.bind(func, thisArg, "hi");\ | |||
skipping to change at line 350 | skipping to change at line 351 | |||
object[funcName] = belt[funcName];\ | object[funcName] = belt[funcName];\ | |||
return object;\ | return object;\ | |||
}, {});\ | }, {});\ | |||
}\ | }\ | |||
}\ | }\ | |||
if (typeof chaining != "undefined") {\ | if (typeof chaining != "undefined") {\ | |||
var even = function(v) { return v % 2 == 0; },\ | var even = function(v) { return v % 2 == 0; },\ | |||
square = function(v) { return v * v; };\ | square = function(v) { return v * v; };\ | |||
\ | \ | |||
var largeArray = belt.range(10000),\ | var largeArray = belt.range(10000),\ | |||
_chaining = _.chain ? _(largeArray).chain() : _(largeArray),\ | _chaining = _(largeArray).chain(),\ | |||
lodashChaining = lodash(largeArray);\ | lodashChaining = lodash(largeArray).chain();\ | |||
}\ | }\ | |||
if (typeof compact != "undefined") {\ | if (typeof compact != "undefined") {\ | |||
var uncompacted = numbers.slice();\ | var uncompacted = numbers.slice();\ | |||
uncompacted[2] = false;\ | uncompacted[2] = false;\ | |||
uncompacted[6] = null;\ | uncompacted[6] = null;\ | |||
uncompacted[18] = "";\ | uncompacted[18] = "";\ | |||
}\ | }\ | |||
if (typeof compose != "undefined") {\ | if (typeof flowRight != "undefined") {\ | |||
var compAddOne = function(n) { return n + 1; },\ | var compAddOne = function(n) { return n + 1; },\ | |||
compAddTwo = function(n) { return n + 2; },\ | compAddTwo = function(n) { return n + 2; },\ | |||
compAddThree = function(n) { return n + 3; };\ | compAddThree = function(n) { return n + 3; };\ | |||
\ | \ | |||
var _composed = _.compose(compAddThree, compAddTwo, compAddOne),\ | var _composed = _.flowRight && _.flowRight(compAddThree, compAddTwo, com | |||
lodashComposed = lodash.compose(compAddThree, compAddTwo, compAddOne | pAddOne),\ | |||
);\ | lodashComposed = lodash.flowRight && lodash.flowRight(compAddThree, | |||
compAddTwo, compAddOne);\ | ||||
}\ | }\ | |||
if (typeof countBy != "undefined" || typeof omit != "undefined") {\ | if (typeof countBy != "undefined" || typeof omit != "undefined") {\ | |||
var wordToNumber = {\ | var wordToNumber = {\ | |||
"one": 1,\ | "one": 1,\ | |||
"two": 2,\ | "two": 2,\ | |||
"three": 3,\ | "three": 3,\ | |||
"four": 4,\ | "four": 4,\ | |||
"five": 5,\ | "five": 5,\ | |||
"six": 6,\ | "six": 6,\ | |||
"seven": 7,\ | "seven": 7,\ | |||
skipping to change at line 415 | skipping to change at line 416 | |||
"thirty-seven": 37,\ | "thirty-seven": 37,\ | |||
"thirty-eight": 38,\ | "thirty-eight": 38,\ | |||
"thirty-nine": 39,\ | "thirty-nine": 39,\ | |||
"forty": 40\ | "forty": 40\ | |||
};\ | };\ | |||
\ | \ | |||
var words = belt.keys(wordToNumber).slice(0, limit);\ | var words = belt.keys(wordToNumber).slice(0, limit);\ | |||
}\ | }\ | |||
if (typeof flatten != "undefined") {\ | if (typeof flatten != "undefined") {\ | |||
var _flattenDeep = _.flatten([[1]])[0] !== 1,\ | var _flattenDeep = _.flatten([[1]])[0] !== 1,\ | |||
lodashFlattenDeep = lodash.flatten([[1]]) !== 1;\ | lodashFlattenDeep = lodash.flatten([[1]])[0] !== 1;\ | |||
}\ | }\ | |||
if (typeof isEqual != "undefined") {\ | if (typeof isEqual != "undefined") {\ | |||
var objectOfPrimitives = {\ | var objectOfPrimitives = {\ | |||
"boolean": true,\ | "boolean": true,\ | |||
"number": 1,\ | "number": 1,\ | |||
"string": "a"\ | "string": "a"\ | |||
};\ | };\ | |||
\ | \ | |||
var objectOfObjects = {\ | var objectOfObjects = {\ | |||
"boolean": new Boolean(true),\ | "boolean": new Boolean(true),\ | |||
skipping to change at line 460 | skipping to change at line 461 | |||
numbers2[index] = index;\ | numbers2[index] = index;\ | |||
numbers3[index] = index;\ | numbers3[index] = index;\ | |||
}\ | }\ | |||
object3["key" + (limit - 1)] = -1;\ | object3["key" + (limit - 1)] = -1;\ | |||
objects3[limit - 1].num = -1;\ | objects3[limit - 1].num = -1;\ | |||
numbers3[limit - 1] = -1;\ | numbers3[limit - 1] = -1;\ | |||
}\ | }\ | |||
if (typeof matches != "undefined") {\ | if (typeof matches != "undefined") {\ | |||
var source = { "num": 9 };\ | var source = { "num": 9 };\ | |||
\ | \ | |||
var _findWhere = _.findWhere || _.find,\ | var _matcher = (_.matches || _.noop)(source),\ | |||
_match = (_.matches || _.createCallback || _.noop)(source);\ | lodashMatcher = (lodash.matches || lodash.noop)(source);\ | |||
\ | ||||
var lodashFindWhere = lodash.findWhere || lodash.find,\ | ||||
lodashMatch = (lodash.matches || lodash.createCallback || lodash.noo | ||||
p)(source);\ | ||||
}\ | }\ | |||
if (typeof multiArrays != "undefined") {\ | if (typeof multiArrays != "undefined") {\ | |||
var twentyValues = belt.shuffle(belt.range(20)),\ | var twentyValues = belt.shuffle(belt.range(20)),\ | |||
fortyValues = belt.shuffle(belt.range(40)),\ | fortyValues = belt.shuffle(belt.range(40)),\ | |||
hundredSortedValues = belt.range(100),\ | hundredSortedValues = belt.range(100),\ | |||
hundredValues = belt.shuffle(hundredSortedValues),\ | hundredValues = belt.shuffle(hundredSortedValues),\ | |||
hundredValues2 = belt.shuffle(hundredValues),\ | hundredValues2 = belt.shuffle(hundredValues),\ | |||
hundredTwentyValues = belt.shuffle(belt.range(120)),\ | hundredTwentyValues = belt.shuffle(belt.range(120)),\ | |||
hundredTwentyValues2 = belt.shuffle(hundredTwentyValues),\ | hundredTwentyValues2 = belt.shuffle(hundredTwentyValues),\ | |||
twoHundredValues = belt.shuffle(belt.range(200)),\ | twoHundredValues = belt.shuffle(belt.range(200)),\ | |||
skipping to change at line 568 | skipping to change at line 566 | |||
}) | }) | |||
.add(otherName, { | .add(otherName, { | |||
'fn': '_chaining.map(square).filter(even).take(100).value()', | 'fn': '_chaining.map(square).filter(even).take(100).value()', | |||
'teardown': 'function chaining(){}' | 'teardown': 'function chaining(){}' | |||
}) | }) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.assign`') | ||||
.add(buildName, { | ||||
'fn': 'lodashAssign({}, object)', | ||||
'teardown': 'function assign(){}' | ||||
}) | ||||
.add(otherName, { | ||||
'fn': '_assign({}, object)', | ||||
'teardown': 'function assign(){}' | ||||
}) | ||||
); | ||||
suites.push( | ||||
Benchmark.Suite('`_.assign` with multiple sources') | ||||
.add(buildName, { | ||||
'fn': 'lodashAssign({}, object, object)', | ||||
'teardown': 'function assign(){}' | ||||
}) | ||||
.add(otherName, { | ||||
'fn': '_assign({}, object, object)', | ||||
'teardown': 'function assign(){}' | ||||
}) | ||||
); | ||||
/*--------------------------------------------------------------------------*/ | ||||
suites.push( | ||||
Benchmark.Suite('`_.bind` (slow path)') | Benchmark.Suite('`_.bind` (slow path)') | |||
.add(buildName, { | .add(buildName, { | |||
'fn': 'lodash.bind(function() { return this.name; }, { "name": "fred" }) ', | 'fn': 'lodash.bind(function() { return this.name; }, { "name": "fred" }) ', | |||
'teardown': 'function bind(){}' | 'teardown': 'function bind(){}' | |||
}) | }) | |||
.add(otherName, { | .add(otherName, { | |||
'fn': '_.bind(function() { return this.name; }, { "name": "fred" })', | 'fn': '_.bind(function() { return this.name; }, { "name": "fred" })', | |||
'teardown': 'function bind(){}' | 'teardown': 'function bind(){}' | |||
}) | }) | |||
); | ); | |||
skipping to change at line 618 | skipping to change at line 642 | |||
}) | }) | |||
.add(otherName, { | .add(otherName, { | |||
'fn': '_boundMultiple()', | 'fn': '_boundMultiple()', | |||
'teardown': 'function bind(){}' | 'teardown': 'function bind(){}' | |||
}) | }) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.bindAll` iterating arguments') | Benchmark.Suite('`_.bindAll`') | |||
.add(buildName, { | ||||
'fn': 'lodash.bindAll.apply(lodash, [bindAllObjects[++bindAllCount]].con | ||||
cat(funcNames))', | ||||
'teardown': 'function bindAll(){}' | ||||
}) | ||||
.add(otherName, { | ||||
'fn': '_.bindAll.apply(_, [bindAllObjects[++bindAllCount]].concat(funcNa | ||||
mes))', | ||||
'teardown': 'function bindAll(){}' | ||||
}) | ||||
); | ||||
suites.push( | ||||
Benchmark.Suite('`_.bindAll` iterating the `object`') | ||||
.add(buildName, { | .add(buildName, { | |||
'fn': 'lodash.bindAll(bindAllObjects[++bindAllCount])', | 'fn': 'lodash.bindAll(bindAllObjects[++bindAllCount], funcNames)', | |||
'teardown': 'function bindAll(){}' | 'teardown': 'function bindAll(){}' | |||
}) | }) | |||
.add(otherName, { | .add(otherName, { | |||
'fn': '_.bindAll(bindAllObjects[++bindAllCount])', | 'fn': '_.bindAll(bindAllObjects[++bindAllCount], funcNames)', | |||
'teardown': 'function bindAll(){}' | 'teardown': 'function bindAll(){}' | |||
}) | }) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.clone` with an array') | Benchmark.Suite('`_.clone` with an array') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.clone(numbers)' | lodash.clone(numbers)' | |||
skipping to change at line 680 | skipping to change at line 692 | |||
}) | }) | |||
.add(otherName, { | .add(otherName, { | |||
'fn': '_.compact(uncompacted)', | 'fn': '_.compact(uncompacted)', | |||
'teardown': 'function compact(){}' | 'teardown': 'function compact(){}' | |||
}) | }) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.compose`') | ||||
.add(buildName, { | ||||
'fn': 'lodash.compose(compAddThree, compAddTwo, compAddOne)', | ||||
'teardown': 'function compose(){}' | ||||
}) | ||||
.add(otherName, { | ||||
'fn': '_.compose(compAddThree, compAddTwo, compAddOne)', | ||||
'teardown': 'function compose(){}' | ||||
}) | ||||
); | ||||
suites.push( | ||||
Benchmark.Suite('composed call') | ||||
.add(buildName, { | ||||
'fn': 'lodashComposed(0)', | ||||
'teardown': 'function compose(){}' | ||||
}) | ||||
.add(otherName, { | ||||
'fn': '_composed(0)', | ||||
'teardown': 'function compose(){}' | ||||
}) | ||||
); | ||||
/*--------------------------------------------------------------------------*/ | ||||
suites.push( | ||||
Benchmark.Suite('`_.countBy` with `callback` iterating an array') | Benchmark.Suite('`_.countBy` with `callback` iterating an array') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.countBy(numbers, function(num) { return num >> 1; })' | lodash.countBy(numbers, function(num) { return num >> 1; })' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.countBy(numbers, function(num) { return num >> 1; })' | _.countBy(numbers, function(num) { return num >> 1; })' | |||
) | ) | |||
); | ); | |||
suites.push( | suites.push( | |||
skipping to change at line 806 | skipping to change at line 792 | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
var result = [];\ | var result = [];\ | |||
_.each(numbers, function(num) {\ | _.each(numbers, function(num) {\ | |||
result.push(num * 2);\ | result.push(num * 2);\ | |||
})' | })' | |||
) | ) | |||
); | ); | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.each` iterating an array with `thisArg` (slow path)') | ||||
.add(buildName, '\ | ||||
var result = [];\ | ||||
lodash.each(numbers, function(num, index) {\ | ||||
result.push(num + this["key" + index]);\ | ||||
}, object)' | ||||
) | ||||
.add(otherName, '\ | ||||
var result = [];\ | ||||
_.each(numbers, function(num, index) {\ | ||||
result.push(num + this["key" + index]);\ | ||||
}, object)' | ||||
) | ||||
); | ||||
suites.push( | ||||
Benchmark.Suite('`_.each` iterating an object') | Benchmark.Suite('`_.each` iterating an object') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
var result = [];\ | var result = [];\ | |||
lodash.each(object, function(num) {\ | lodash.each(object, function(num) {\ | |||
result.push(num * 2);\ | result.push(num * 2);\ | |||
})' | })' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
var result = [];\ | var result = [];\ | |||
_.each(object, function(num) {\ | _.each(object, function(num) {\ | |||
skipping to change at line 870 | skipping to change at line 840 | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.every(object, function(num) {\ | _.every(object, function(num) {\ | |||
return num < limit;\ | return num < limit;\ | |||
})' | })' | |||
) | ) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.extend`') | ||||
.add(buildName, '\ | ||||
lodash.extend({}, object)' | ||||
) | ||||
.add(otherName, '\ | ||||
_.extend({}, object)' | ||||
) | ||||
); | ||||
/*--------------------------------------------------------------------------*/ | ||||
suites.push( | ||||
Benchmark.Suite('`_.filter` iterating an array') | Benchmark.Suite('`_.filter` iterating an array') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.filter(numbers, function(num) {\ | lodash.filter(numbers, function(num) {\ | |||
return num % 2;\ | return num % 2;\ | |||
})' | })' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.filter(numbers, function(num) {\ | _.filter(numbers, function(num) {\ | |||
return num % 2;\ | return num % 2;\ | |||
})' | })' | |||
) | ) | |||
); | ); | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.filter` iterating an array with `thisArg` (slow path)') | ||||
.add(buildName, '\ | ||||
lodash.filter(numbers, function(num, index) {\ | ||||
return this["key" + index] % 2;\ | ||||
}, object)' | ||||
) | ||||
.add(otherName, '\ | ||||
_.filter(numbers, function(num, index) {\ | ||||
return this["key" + index] % 2;\ | ||||
}, object)' | ||||
) | ||||
); | ||||
suites.push( | ||||
Benchmark.Suite('`_.filter` iterating an object') | Benchmark.Suite('`_.filter` iterating an object') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.filter(object, function(num) {\ | lodash.filter(object, function(num) {\ | |||
return num % 2\ | return num % 2\ | |||
})' | })' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.filter(object, function(num) {\ | _.filter(object, function(num) {\ | |||
return num % 2\ | return num % 2\ | |||
})' | })' | |||
) | ) | |||
); | ); | |||
suites.push( | ||||
Benchmark.Suite('`_.filter` with `_.matches` shorthand') | ||||
.add(buildName, { | ||||
'fn': 'lodash.filter(objects, source)', | ||||
'teardown': 'function matches(){}' | ||||
}) | ||||
.add(otherName, { | ||||
'fn': '_.filter(objects, source)', | ||||
'teardown': 'function matches(){}' | ||||
}) | ||||
); | ||||
suites.push( | ||||
Benchmark.Suite('`_.filter` with `_.matches` predicate') | ||||
.add(buildName, { | ||||
'fn': 'lodash.filter(objects, lodashMatcher)', | ||||
'teardown': 'function matches(){}' | ||||
}) | ||||
.add(otherName, { | ||||
'fn': '_.filter(objects, _matcher)', | ||||
'teardown': 'function matches(){}' | ||||
}) | ||||
); | ||||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.find` iterating an array') | Benchmark.Suite('`_.find` iterating an array') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.find(numbers, function(num) {\ | lodash.find(numbers, function(num) {\ | |||
return num === (limit - 1);\ | return num === (limit - 1);\ | |||
})' | })' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
skipping to change at line 953 | skipping to change at line 921 | |||
return /\D9$/.test(key);\ | return /\D9$/.test(key);\ | |||
})' | })' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.find(object, function(value, key) {\ | _.find(object, function(value, key) {\ | |||
return /\D9$/.test(key);\ | return /\D9$/.test(key);\ | |||
})' | })' | |||
) | ) | |||
); | ); | |||
// Avoid Underscore induced `OutOfMemoryError` in Rhino, Narwhal, and Ringo. | // Avoid Underscore induced `OutOfMemoryError` in Rhino and Ringo. | |||
if (!isJava) { | suites.push( | |||
suites.push( | Benchmark.Suite('`_.find` with `_.matches` shorthand') | |||
Benchmark.Suite('`_.find` with `properties`') | .add(buildName, { | |||
.add(buildName, { | 'fn': 'lodash.find(objects, source)', | |||
'fn': 'lodashFindWhere(objects, source)', | 'teardown': 'function matches(){}' | |||
'teardown': 'function matches(){}' | }) | |||
}) | .add(otherName, { | |||
.add(otherName, { | 'fn': '_.find(objects, source)', | |||
'fn': '_findWhere(objects, source)', | 'teardown': 'function matches(){}' | |||
'teardown': 'function matches(){}' | }) | |||
}) | ); | |||
); | ||||
} | ||||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.flatten`') | Benchmark.Suite('`_.flatten`') | |||
.add(buildName, { | .add(buildName, { | |||
'fn': 'lodash.flatten(nestedNumbers, !lodashFlattenDeep)', | 'fn': 'lodash.flatten(nestedNumbers, !lodashFlattenDeep)', | |||
'teardown': 'function flatten(){}' | 'teardown': 'function flatten(){}' | |||
}) | }) | |||
.add(otherName, { | .add(otherName, { | |||
'fn': '_.flatten(nestedNumbers, !_flattenDeep)', | 'fn': '_.flatten(nestedNumbers, !_flattenDeep)', | |||
'teardown': 'function flatten(){}' | 'teardown': 'function flatten(){}' | |||
}) | }) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | ||||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.flatten` nested arrays of numbers with `isDeep`') | Benchmark.Suite('`_.flattenDeep` nested arrays of numbers') | |||
.add(buildName, { | .add(buildName, { | |||
'fn': 'lodash.flatten(nestedNumbers, lodashFlattenDeep)', | 'fn': 'lodash.flattenDeep(nestedNumbers)', | |||
'teardown': 'function flatten(){}' | 'teardown': 'function flatten(){}' | |||
}) | }) | |||
.add(otherName, { | .add(otherName, { | |||
'fn': '_.flatten(nestedNumbers, _flattenDeep)', | 'fn': '_.flattenDeep(nestedNumbers)', | |||
'teardown': 'function flatten(){}' | 'teardown': 'function flatten(){}' | |||
}) | }) | |||
); | ); | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.flatten` nest arrays of objects with `isDeep`') | Benchmark.Suite('`_.flattenDeep` nest arrays of objects') | |||
.add(buildName, { | .add(buildName, { | |||
'fn': 'lodash.flatten(nestedObjects, lodashFlattenDeep)', | 'fn': 'lodash.flattenDeep(nestedObjects)', | |||
'teardown': 'function flatten(){}' | 'teardown': 'function flatten(){}' | |||
}) | }) | |||
.add(otherName, { | .add(otherName, { | |||
'fn': '_.flatten(nestedObjects, _flattenDeep)', | 'fn': '_.flattenDeep(nestedObjects)', | |||
'teardown': 'function flatten(){}' | 'teardown': 'function flatten(){}' | |||
}) | }) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.flowRight`') | ||||
.add(buildName, { | ||||
'fn': 'lodash.flowRight(compAddThree, compAddTwo, compAddOne)', | ||||
'teardown': 'function flowRight(){}' | ||||
}) | ||||
.add(otherName, { | ||||
'fn': '_.flowRight(compAddThree, compAddTwo, compAddOne)', | ||||
'teardown': 'function flowRight(){}' | ||||
}) | ||||
); | ||||
suites.push( | ||||
Benchmark.Suite('composed call') | ||||
.add(buildName, { | ||||
'fn': 'lodashComposed(0)', | ||||
'teardown': 'function flowRight(){}' | ||||
}) | ||||
.add(otherName, { | ||||
'fn': '_composed(0)', | ||||
'teardown': 'function flowRight(){}' | ||||
}) | ||||
); | ||||
/*--------------------------------------------------------------------------*/ | ||||
suites.push( | ||||
Benchmark.Suite('`_.functions`') | Benchmark.Suite('`_.functions`') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.functions(lodash)' | lodash.functions(lodash)' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.functions(lodash)' | _.functions(lodash)' | |||
) | ) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
skipping to change at line 1059 | skipping to change at line 1053 | |||
'fn': '_.groupBy(wordToNumber, function(num) { return num >> 1; })', | 'fn': '_.groupBy(wordToNumber, function(num) { return num >> 1; })', | |||
'teardown': 'function countBy(){}' | 'teardown': 'function countBy(){}' | |||
}) | }) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.includes` searching an array') | Benchmark.Suite('`_.includes` searching an array') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.include(numbers, limit - 1)' | lodash.includes(numbers, limit - 1)' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.include(numbers, limit - 1)' | _.includes(numbers, limit - 1)' | |||
) | ) | |||
); | ); | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.includes` searching an object') | Benchmark.Suite('`_.includes` searching an object') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.include(object, limit - 1)' | lodash.includes(object, limit - 1)' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.include(object, limit - 1)' | _.includes(object, limit - 1)' | |||
) | ) | |||
); | ); | |||
if (lodash.include('ab', 'ab') && _.include('ab', 'ab')) { | if (lodash.includes('ab', 'ab') && _.includes('ab', 'ab')) { | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.includes` searching a string') | Benchmark.Suite('`_.includes` searching a string') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.include(strNumbers, "," + (limit - 1))' | lodash.includes(strNumbers, "," + (limit - 1))' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.include(strNumbers, "," + (limit - 1))' | _.includes(strNumbers, "," + (limit - 1))' | |||
) | ) | |||
); | ); | |||
} | } | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.indexBy` with `callback` iterating an array') | ||||
.add(buildName, '\ | ||||
lodash.indexBy(numbers, function(num) { return num >> 1; })' | ||||
) | ||||
.add(otherName, '\ | ||||
_.indexBy(numbers, function(num) { return num >> 1; })' | ||||
) | ||||
); | ||||
suites.push( | ||||
Benchmark.Suite('`_.indexBy` with `property` name iterating an array') | ||||
.add(buildName, { | ||||
'fn': 'lodash.indexBy(words, "length")', | ||||
'teardown': 'function countBy(){}' | ||||
}) | ||||
.add(otherName, { | ||||
'fn': '_.indexBy(words, "length")', | ||||
'teardown': 'function countBy(){}' | ||||
}) | ||||
); | ||||
suites.push( | ||||
Benchmark.Suite('`_.indexBy` with `callback` iterating an object') | ||||
.add(buildName, { | ||||
'fn': 'lodash.indexBy(wordToNumber, function(num) { return num >> 1; })' | ||||
, | ||||
'teardown': 'function countBy(){}' | ||||
}) | ||||
.add(otherName, { | ||||
'fn': '_.indexBy(wordToNumber, function(num) { return num >> 1; })', | ||||
'teardown': 'function countBy(){}' | ||||
}) | ||||
); | ||||
/*--------------------------------------------------------------------------*/ | ||||
suites.push( | ||||
Benchmark.Suite('`_.indexOf`') | Benchmark.Suite('`_.indexOf`') | |||
.add(buildName, { | .add(buildName, { | |||
'fn': 'lodash.indexOf(hundredSortedValues, 99)', | 'fn': 'lodash.indexOf(hundredSortedValues, 99)', | |||
'teardown': 'function multiArrays(){}' | 'teardown': 'function multiArrays(){}' | |||
}) | }) | |||
.add(otherName, { | .add(otherName, { | |||
'fn': '_.indexOf(hundredSortedValues, 99)', | 'fn': '_.indexOf(hundredSortedValues, 99)', | |||
'teardown': 'function multiArrays(){}' | 'teardown': 'function multiArrays(){}' | |||
}) | }) | |||
); | ); | |||
suites.push( | ||||
Benchmark.Suite('`_.indexOf` performing a binary search') | ||||
.add(buildName, { | ||||
'fn': 'lodash.indexOf(hundredSortedValues, 99, true)', | ||||
'teardown': 'function multiArrays(){}' | ||||
}) | ||||
.add(otherName, { | ||||
'fn': '_.indexOf(hundredSortedValues, 99, true)', | ||||
'teardown': 'function multiArrays(){}' | ||||
}) | ||||
); | ||||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.intersection`') | Benchmark.Suite('`_.intersection`') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.intersection(numbers, twoNumbers, fourNumbers)' | lodash.intersection(numbers, twoNumbers, fourNumbers)' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.intersection(numbers, twoNumbers, fourNumbers)' | _.intersection(numbers, twoNumbers, fourNumbers)' | |||
) | ) | |||
skipping to change at line 1189 | skipping to change at line 1135 | |||
lodash.invert(object)' | lodash.invert(object)' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.invert(object)' | _.invert(object)' | |||
) | ) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.invoke` iterating an array') | Benchmark.Suite('`_.invokeMap` iterating an array') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.invoke(numbers, "toFixed")' | lodash.invokeMap(numbers, "toFixed")' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.invoke(numbers, "toFixed")' | _.invokeMap(numbers, "toFixed")' | |||
) | ) | |||
); | ); | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.invoke` with arguments iterating an array') | Benchmark.Suite('`_.invokeMap` with arguments iterating an array') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.invoke(numbers, "toFixed", 1)' | lodash.invokeMap(numbers, "toFixed", 1)' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.invoke(numbers, "toFixed", 1)' | _.invokeMap(numbers, "toFixed", 1)' | |||
) | ) | |||
); | ); | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.invoke` with a function for `methodName` iterating an ar ray') | Benchmark.Suite('`_.invokeMap` with a function for `path` iterating an array ') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.invoke(numbers, Number.prototype.toFixed, 1)' | lodash.invokeMap(numbers, Number.prototype.toFixed, 1)' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.invoke(numbers, Number.prototype.toFixed, 1)' | _.invokeMap(numbers, Number.prototype.toFixed, 1)' | |||
) | ) | |||
); | ); | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.invoke` iterating an object') | Benchmark.Suite('`_.invokeMap` iterating an object') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.invoke(object, "toFixed", 1)' | lodash.invokeMap(object, "toFixed", 1)' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.invoke(object, "toFixed", 1)' | _.invokeMap(object, "toFixed", 1)' | |||
) | ) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.isEqual` comparing primitives') | Benchmark.Suite('`_.isEqual` comparing primitives') | |||
.add(buildName, { | .add(buildName, { | |||
'fn': '\ | 'fn': '\ | |||
lodash.isEqual(1, "1");\ | lodash.isEqual(1, "1");\ | |||
skipping to change at line 1386 | skipping to change at line 1332 | |||
.add(buildName, { | .add(buildName, { | |||
'fn': 'lodash.lastIndexOf(hundredSortedValues, 0)', | 'fn': 'lodash.lastIndexOf(hundredSortedValues, 0)', | |||
'teardown': 'function multiArrays(){}' | 'teardown': 'function multiArrays(){}' | |||
}) | }) | |||
.add(otherName, { | .add(otherName, { | |||
'fn': '_.lastIndexOf(hundredSortedValues, 0)', | 'fn': '_.lastIndexOf(hundredSortedValues, 0)', | |||
'teardown': 'function multiArrays(){}' | 'teardown': 'function multiArrays(){}' | |||
}) | }) | |||
); | ); | |||
suites.push( | ||||
Benchmark.Suite('`_.lastIndexOf` performing a binary search') | ||||
.add(buildName, { | ||||
'fn': 'lodash.lastIndexOf(hundredSortedValues, 0, true)', | ||||
'teardown': 'function multiArrays(){}' | ||||
}) | ||||
.add(otherName, { | ||||
'fn': '_.lastIndexOf(hundredSortedValues, 0, true)', | ||||
'teardown': 'function multiArrays(){}' | ||||
}) | ||||
); | ||||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.map` iterating an array') | Benchmark.Suite('`_.map` iterating an array') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.map(objects, function(value) {\ | lodash.map(objects, function(value) {\ | |||
return value.num;\ | return value.num;\ | |||
})' | })' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.map(objects, function(value) {\ | _.map(objects, function(value) {\ | |||
return value.num;\ | return value.num;\ | |||
})' | })' | |||
) | ) | |||
); | ); | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.map` with `thisArg` iterating an array (slow path)') | ||||
.add(buildName, '\ | ||||
lodash.map(objects, function(value, index) {\ | ||||
return this["key" + index] + value.num;\ | ||||
}, object)' | ||||
) | ||||
.add(otherName, '\ | ||||
_.map(objects, function(value, index) {\ | ||||
return this["key" + index] + value.num;\ | ||||
}, object)' | ||||
) | ||||
); | ||||
suites.push( | ||||
Benchmark.Suite('`_.map` iterating an object') | Benchmark.Suite('`_.map` iterating an object') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.map(object, function(value) {\ | lodash.map(object, function(value) {\ | |||
return value;\ | return value;\ | |||
})' | })' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.map(object, function(value) {\ | _.map(object, function(value) {\ | |||
return value;\ | return value;\ | |||
})' | })' | |||
) | ) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | ||||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.matches` predicate') | Benchmark.Suite('`_.map` with `_.property` shorthand') | |||
.add(buildName, { | .add(buildName, '\ | |||
'fn': 'lodash.filter(objects, lodashMatch)', | lodash.map(objects, "num")' | |||
'teardown': 'function matches(){}' | ) | |||
}) | .add(otherName, '\ | |||
.add(otherName, { | _.map(objects, "num")' | |||
'fn': '_.filter(objects, _match)', | ) | |||
'teardown': 'function matches(){}' | ||||
}) | ||||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.max`') | Benchmark.Suite('`_.max`') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.max(numbers)' | lodash.max(numbers)' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
skipping to change at line 1507 | skipping to change at line 1423 | |||
}) | }) | |||
.add(otherName, { | .add(otherName, { | |||
'fn': '_.omit(wordToNumber, words)', | 'fn': '_.omit(wordToNumber, words)', | |||
'teardown': 'function omit(){}' | 'teardown': 'function omit(){}' | |||
}) | }) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.pairs`') | ||||
.add(buildName, '\ | ||||
lodash.pairs(object)' | ||||
) | ||||
.add(otherName, '\ | ||||
_.pairs(object)' | ||||
) | ||||
); | ||||
/*--------------------------------------------------------------------------*/ | ||||
suites.push( | ||||
Benchmark.Suite('`_.partial` (slow path)') | Benchmark.Suite('`_.partial` (slow path)') | |||
.add(buildName, { | .add(buildName, { | |||
'fn': 'lodash.partial(function(greeting) { return greeting + " " + this. name; }, "hi")', | 'fn': 'lodash.partial(function(greeting) { return greeting + " " + this. name; }, "hi")', | |||
'teardown': 'function partial(){}' | 'teardown': 'function partial(){}' | |||
}) | }) | |||
.add(otherName, { | .add(otherName, { | |||
'fn': '_.partial(function(greeting) { return greeting + " " + this.name; }, "hi")', | 'fn': '_.partial(function(greeting) { return greeting + " " + this.name; }, "hi")', | |||
'teardown': 'function partial(){}' | 'teardown': 'function partial(){}' | |||
}) | }) | |||
); | ); | |||
skipping to change at line 1559 | skipping to change at line 1463 | |||
})' | })' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.partition(numbers, function(num) {\ | _.partition(numbers, function(num) {\ | |||
return num % 2;\ | return num % 2;\ | |||
})' | })' | |||
) | ) | |||
); | ); | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.partition` iterating an array with `thisArg` (slow path) | ||||
') | ||||
.add(buildName, '\ | ||||
lodash.partition(numbers, function(num, index) {\ | ||||
return this["key" + index] % 2;\ | ||||
}, object)' | ||||
) | ||||
.add(otherName, '\ | ||||
_.partition(numbers, function(num, index) {\ | ||||
return this["key" + index] % 2;\ | ||||
}, object)' | ||||
) | ||||
); | ||||
suites.push( | ||||
Benchmark.Suite('`_.partition` iterating an object') | Benchmark.Suite('`_.partition` iterating an object') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.partition(object, function(num) {\ | lodash.partition(object, function(num) {\ | |||
return num % 2;\ | return num % 2;\ | |||
})' | })' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.partition(object, function(num) {\ | _.partition(object, function(num) {\ | |||
return num % 2;\ | return num % 2;\ | |||
})' | })' | |||
skipping to change at line 1601 | skipping to change at line 1491 | |||
lodash.pick(object, "key6", "key13")' | lodash.pick(object, "key6", "key13")' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.pick(object, "key6", "key13")' | _.pick(object, "key6", "key13")' | |||
) | ) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.pluck`') | ||||
.add(buildName, '\ | ||||
lodash.pluck(objects, "num")' | ||||
) | ||||
.add(otherName, '\ | ||||
_.pluck(objects, "num")' | ||||
) | ||||
); | ||||
/*--------------------------------------------------------------------------*/ | ||||
suites.push( | ||||
Benchmark.Suite('`_.reduce` iterating an array') | Benchmark.Suite('`_.reduce` iterating an array') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.reduce(numbers, function(result, value, index) {\ | lodash.reduce(numbers, function(result, value, index) {\ | |||
result[index] = value;\ | result[index] = value;\ | |||
return result;\ | return result;\ | |||
}, {})' | }, {})' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.reduce(numbers, function(result, value, index) {\ | _.reduce(numbers, function(result, value, index) {\ | |||
result[index] = value;\ | result[index] = value;\ | |||
skipping to change at line 1695 | skipping to change at line 1573 | |||
})' | })' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.reject(numbers, function(num) {\ | _.reject(numbers, function(num) {\ | |||
return num % 2;\ | return num % 2;\ | |||
})' | })' | |||
) | ) | |||
); | ); | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.reject` iterating an array with `thisArg` (slow path)') | ||||
.add(buildName, '\ | ||||
lodash.reject(numbers, function(num, index) {\ | ||||
return this["key" + index] % 2;\ | ||||
}, object)' | ||||
) | ||||
.add(otherName, '\ | ||||
_.reject(numbers, function(num, index) {\ | ||||
return this["key" + index] % 2;\ | ||||
}, object)' | ||||
) | ||||
); | ||||
suites.push( | ||||
Benchmark.Suite('`_.reject` iterating an object') | Benchmark.Suite('`_.reject` iterating an object') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.reject(object, function(num) {\ | lodash.reject(object, function(num) {\ | |||
return num % 2;\ | return num % 2;\ | |||
})' | })' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.reject(object, function(num) {\ | _.reject(object, function(num) {\ | |||
return num % 2;\ | return num % 2;\ | |||
})' | })' | |||
) | ) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.sample` with an `n`') | Benchmark.Suite('`_.sampleSize`') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.sample(numbers, limit / 2)' | lodash.sampleSize(numbers, limit / 2)' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.sample(numbers, limit / 2)' | _.sampleSize(numbers, limit / 2)' | |||
) | ) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.shuffle`') | Benchmark.Suite('`_.shuffle`') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.shuffle(numbers)' | lodash.shuffle(numbers)' | |||
) | ) | |||
skipping to change at line 1775 | skipping to change at line 1639 | |||
})' | })' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.some(numbers, function(num) {\ | _.some(numbers, function(num) {\ | |||
return num == (limit - 1);\ | return num == (limit - 1);\ | |||
})' | })' | |||
) | ) | |||
); | ); | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.some` with `thisArg` iterating an array (slow path)') | ||||
.add(buildName, '\ | ||||
lodash.some(objects, function(value, index) {\ | ||||
return this["key" + index] == (limit - 1);\ | ||||
}, object)' | ||||
) | ||||
.add(otherName, '\ | ||||
_.some(objects, function(value, index) {\ | ||||
return this["key" + index] == (limit - 1);\ | ||||
}, object)' | ||||
) | ||||
); | ||||
suites.push( | ||||
Benchmark.Suite('`_.some` iterating an object') | Benchmark.Suite('`_.some` iterating an object') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.some(object, function(num) {\ | lodash.some(object, function(num) {\ | |||
return num == (limit - 1);\ | return num == (limit - 1);\ | |||
})' | })' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.some(object, function(num) {\ | _.some(object, function(num) {\ | |||
return num == (limit - 1);\ | return num == (limit - 1);\ | |||
})' | })' | |||
skipping to change at line 1815 | skipping to change at line 1665 | |||
Benchmark.Suite('`_.sortBy` with `callback`') | Benchmark.Suite('`_.sortBy` with `callback`') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.sortBy(numbers, function(num) { return Math.sin(num); })' | lodash.sortBy(numbers, function(num) { return Math.sin(num); })' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.sortBy(numbers, function(num) { return Math.sin(num); })' | _.sortBy(numbers, function(num) { return Math.sin(num); })' | |||
) | ) | |||
); | ); | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.sortBy` with `callback` and `thisArg` (slow path)') | ||||
.add(buildName, '\ | ||||
lodash.sortBy(numbers, function(num) { return this.sin(num); }, Math)' | ||||
) | ||||
.add(otherName, '\ | ||||
_.sortBy(numbers, function(num) { return this.sin(num); }, Math)' | ||||
) | ||||
); | ||||
suites.push( | ||||
Benchmark.Suite('`_.sortBy` with `property` name') | Benchmark.Suite('`_.sortBy` with `property` name') | |||
.add(buildName, { | .add(buildName, { | |||
'fn': 'lodash.sortBy(words, "length")', | 'fn': 'lodash.sortBy(words, "length")', | |||
'teardown': 'function countBy(){}' | 'teardown': 'function countBy(){}' | |||
}) | }) | |||
.add(otherName, { | .add(otherName, { | |||
'fn': '_.sortBy(words, "length")', | 'fn': '_.sortBy(words, "length")', | |||
'teardown': 'function countBy(){}' | 'teardown': 'function countBy(){}' | |||
}) | }) | |||
); | ); | |||
skipping to change at line 1848 | skipping to change at line 1688 | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.sortedIndex`') | Benchmark.Suite('`_.sortedIndex`') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.sortedIndex(numbers, limit)' | lodash.sortedIndex(numbers, limit)' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.sortedIndex(numbers, limit)' | _.sortedIndex(numbers, limit)' | |||
) | ) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | ||||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.sortedIndex` with `callback`') | Benchmark.Suite('`_.sortedIndexBy`') | |||
.add(buildName, { | .add(buildName, { | |||
'fn': '\ | 'fn': '\ | |||
lodash.sortedIndex(words, "twenty-five", function(value) {\ | lodash.sortedIndexBy(words, "twenty-five", function(value) {\ | |||
return wordToNumber[value];\ | return wordToNumber[value];\ | |||
})', | })', | |||
'teardown': 'function countBy(){}' | 'teardown': 'function countBy(){}' | |||
}) | }) | |||
.add(otherName, { | .add(otherName, { | |||
'fn': '\ | 'fn': '\ | |||
_.sortedIndex(words, "twenty-five", function(value) {\ | _.sortedIndexBy(words, "twenty-five", function(value) {\ | |||
return wordToNumber[value];\ | return wordToNumber[value];\ | |||
})', | })', | |||
'teardown': 'function countBy(){}' | 'teardown': 'function countBy(){}' | |||
}) | }) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.sortedIndexOf`') | ||||
.add(buildName, { | ||||
'fn': 'lodash.sortedIndexOf(hundredSortedValues, 99)', | ||||
'teardown': 'function multiArrays(){}' | ||||
}) | ||||
.add(otherName, { | ||||
'fn': '_.sortedIndexOf(hundredSortedValues, 99)', | ||||
'teardown': 'function multiArrays(){}' | ||||
}) | ||||
); | ||||
/*--------------------------------------------------------------------------*/ | ||||
suites.push( | ||||
Benchmark.Suite('`_.sortedLastIndexOf`') | ||||
.add(buildName, { | ||||
'fn': 'lodash.sortedLastIndexOf(hundredSortedValues, 0)', | ||||
'teardown': 'function multiArrays(){}' | ||||
}) | ||||
.add(otherName, { | ||||
'fn': '_.sortedLastIndexOf(hundredSortedValues, 0)', | ||||
'teardown': 'function multiArrays(){}' | ||||
}) | ||||
); | ||||
/*--------------------------------------------------------------------------*/ | ||||
suites.push( | ||||
Benchmark.Suite('`_.sum`') | ||||
.add(buildName, '\ | ||||
lodash.sum(numbers)' | ||||
) | ||||
.add(otherName, '\ | ||||
_.sum(numbers)' | ||||
) | ||||
); | ||||
/*--------------------------------------------------------------------------*/ | ||||
suites.push( | ||||
Benchmark.Suite('`_.template` (slow path)') | Benchmark.Suite('`_.template` (slow path)') | |||
.add(buildName, { | .add(buildName, { | |||
'fn': 'lodash.template(tpl)(tplData)', | 'fn': 'lodash.template(tpl)(tplData)', | |||
'teardown': 'function template(){}' | 'teardown': 'function template(){}' | |||
}) | }) | |||
.add(otherName, { | .add(otherName, { | |||
'fn': '_.template(tpl)(tplData)', | 'fn': '_.template(tpl)(tplData)', | |||
'teardown': 'function template(){}' | 'teardown': 'function template(){}' | |||
}) | }) | |||
); | ); | |||
skipping to change at line 1918 | skipping to change at line 1800 | |||
.add(buildName, '\ | .add(buildName, '\ | |||
var result = [];\ | var result = [];\ | |||
lodash.times(limit, function(n) { result.push(n); })' | lodash.times(limit, function(n) { result.push(n); })' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
var result = [];\ | var result = [];\ | |||
_.times(limit, function(n) { result.push(n); })' | _.times(limit, function(n) { result.push(n); })' | |||
) | ) | |||
); | ); | |||
suites.push( | ||||
Benchmark.Suite('`_.times` with `thisArg` (slow path)') | ||||
.add(buildName, '\ | ||||
var result = [];\ | ||||
lodash.times(limit, function(n) { result.push(this.sin(n)); }, Math)' | ||||
) | ||||
.add(otherName, '\ | ||||
var result = [];\ | ||||
_.times(limit, function(n) { result.push(this.sin(n)); }, Math)' | ||||
) | ||||
); | ||||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.toArray` with an array (edge case)') | Benchmark.Suite('`_.toArray` with an array (edge case)') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.toArray(numbers)' | lodash.toArray(numbers)' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.toArray(numbers)' | _.toArray(numbers)' | |||
) | ) | |||
skipping to change at line 1955 | skipping to change at line 1825 | |||
lodash.toArray(object)' | lodash.toArray(object)' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.toArray(object)' | _.toArray(object)' | |||
) | ) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.toPairs`') | ||||
.add(buildName, '\ | ||||
lodash.toPairs(object)' | ||||
) | ||||
.add(otherName, '\ | ||||
_.toPairs(object)' | ||||
) | ||||
); | ||||
/*--------------------------------------------------------------------------*/ | ||||
suites.push( | ||||
Benchmark.Suite('`_.unescape` string without html entities') | Benchmark.Suite('`_.unescape` string without html entities') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.unescape("`&`, `<`, `>`, `\\"`, and `\'`")' | lodash.unescape("`&`, `<`, `>`, `\\"`, and `\'`")' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.unescape("`&`, `<`, `>`, `\\"`, and `\'`")' | _.unescape("`&`, `<`, `>`, `\\"`, and `\'`")' | |||
) | ) | |||
); | ); | |||
suites.push( | suites.push( | |||
skipping to change at line 2011 | skipping to change at line 1893 | |||
Benchmark.Suite('`_.uniq`') | Benchmark.Suite('`_.uniq`') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.uniq(numbers.concat(twoNumbers, fourNumbers))' | lodash.uniq(numbers.concat(twoNumbers, fourNumbers))' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.uniq(numbers.concat(twoNumbers, fourNumbers))' | _.uniq(numbers.concat(twoNumbers, fourNumbers))' | |||
) | ) | |||
); | ); | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.uniq` with `callback`') | ||||
.add(buildName, '\ | ||||
lodash.uniq(numbers.concat(twoNumbers, fourNumbers), function(num) {\ | ||||
return num % 2;\ | ||||
})' | ||||
) | ||||
.add(otherName, '\ | ||||
_.uniq(numbers.concat(twoNumbers, fourNumbers), function(num) {\ | ||||
return num % 2;\ | ||||
})' | ||||
) | ||||
); | ||||
suites.push( | ||||
Benchmark.Suite('`_.uniq` iterating an array of 200 elements') | Benchmark.Suite('`_.uniq` iterating an array of 200 elements') | |||
.add(buildName, { | .add(buildName, { | |||
'fn': 'lodash.uniq(twoHundredValues)', | 'fn': 'lodash.uniq(twoHundredValues)', | |||
'teardown': 'function multiArrays(){}' | 'teardown': 'function multiArrays(){}' | |||
}) | }) | |||
.add(otherName, { | .add(otherName, { | |||
'fn': '_.uniq(twoHundredValues)', | 'fn': '_.uniq(twoHundredValues)', | |||
'teardown': 'function multiArrays(){}' | 'teardown': 'function multiArrays(){}' | |||
}) | }) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.values`') | Benchmark.Suite('`_.uniqBy`') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.values(object)' | lodash.uniqBy(numbers.concat(twoNumbers, fourNumbers), function(num) {\ | |||
return num % 2;\ | ||||
})' | ||||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
_.values(object)' | _.uniqBy(numbers.concat(twoNumbers, fourNumbers), function(num) {\ | |||
return num % 2;\ | ||||
})' | ||||
) | ) | |||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.where`') | Benchmark.Suite('`_.values`') | |||
.add(buildName, { | .add(buildName, '\ | |||
'fn': 'lodash.where(objects, source)', | lodash.values(object)' | |||
'teardown': 'function matches(){}' | ) | |||
}) | .add(otherName, '\ | |||
.add(otherName, { | _.values(object)' | |||
'fn': '_.where(objects, source)', | ) | |||
'teardown': 'function matches(){}' | ||||
}) | ||||
); | ); | |||
/*--------------------------------------------------------------------------*/ | /*--------------------------------------------------------------------------*/ | |||
suites.push( | suites.push( | |||
Benchmark.Suite('`_.without`') | Benchmark.Suite('`_.without`') | |||
.add(buildName, '\ | .add(buildName, '\ | |||
lodash.without(numbers, 9, 12, 14, 15)' | lodash.without(numbers, 9, 12, 14, 15)' | |||
) | ) | |||
.add(otherName, '\ | .add(otherName, '\ | |||
End of changes. 79 change blocks. | ||||
359 lines changed or deleted | 225 lines changed or added |