3 /** Used to access the Firebug Lite panel (set by `run`). */
6 /** Used as a safe reference for `undefined` in pre ES5 environments. */
9 /** Used as a reference to the global object. */
10 var root = typeof global == 'object' && global || this;
12 /** Method and object shortcuts. */
13 var phantom = root.phantom,
14 amd = root.define && define.amd,
15 argv = root.process && process.argv,
16 document = !phantom && root.document,
18 params = root.arguments,
21 /** Add `console.log()` support for Rhino and RingoJS. */
22 var console = root.console || (root.console = { 'log': root.print });
24 /** The file path of the lodash file to test. */
25 var filePath = (function() {
30 result = params = phantom.args;
33 result = params = system.args;
36 result = params = argv;
40 var last = result[result.length - 1];
41 result = (result.length > min && !/perf(?:\.js)?$/.test(last)) ? last : '../lodash.js';
45 result = require('fs').realpathSync(result);
49 result = require.resolve(result);
55 /** Used to match path separators. */
56 var rePathSeparator = /[\/\\]/;
58 /** Used to detect primitive types. */
59 var rePrimitive = /^(?:boolean|number|string|undefined)$/;
61 /** Used to match RegExp special characters. */
62 var reSpecialChars = /[.*+?^=!:${}()|[\]\/\\]/g;
64 /** The `ui` object. */
65 var ui = root.ui || (root.ui = {
66 'buildPath': basename(filePath, '.js'),
67 'otherPath': 'underscore'
70 /** The lodash build basename. */
71 var buildName = root.buildName = basename(ui.buildPath, '.js');
73 /** The other library basename. */
74 var otherName = root.otherName = (function() {
75 var result = basename(ui.otherPath, '.js');
76 return result + (result == buildName ? ' (2)' : '');
79 /** Used to score performance. */
80 var score = { 'a': [], 'b': [] };
82 /** Used to queue benchmark suites. */
85 /** Use a single "load" function. */
86 var load = (typeof require == 'function' && !amd)
91 var lodash = root.lodash || (root.lodash = (
92 lodash = load(filePath) || root._,
93 lodash = lodash._ || lodash,
94 (lodash.runInContext ? lodash.runInContext(root) : lodash),
98 /** Load Underscore. */
99 var _ = root.underscore || (root.underscore = (
100 _ = load('../vendor/underscore/underscore.js') || root._,
104 /** Load Benchmark.js. */
105 var Benchmark = root.Benchmark || (root.Benchmark = (
106 Benchmark = load('../node_modules/benchmark/benchmark.js') || root.Benchmark,
107 Benchmark = Benchmark.Benchmark || Benchmark,
108 Benchmark.runInContext(lodash.extend({}, root, { '_': lodash }))
111 /*--------------------------------------------------------------------------*/
114 * Gets the basename of the given `filePath`. If the file `extension` is passed,
115 * it will be removed from the basename.
118 * @param {string} path The file path to inspect.
119 * @param {string} extension The extension to remove.
120 * @returns {string} Returns the basename.
122 function basename(filePath, extension) {
123 var result = (filePath || '').split(rePathSeparator).pop();
124 return (arguments.length < 2)
126 : result.replace(RegExp(extension.replace(reSpecialChars, '\\$&') + '$'), '');
130 * Computes the geometric mean (log-average) of an array of values.
131 * See http://en.wikipedia.org/wiki/Geometric_mean#Relationship_with_arithmetic_mean_of_logarithms.
134 * @param {Array} array The array of values.
135 * @returns {number} The geometric mean.
137 function getGeometricMean(array) {
138 return Math.pow(Math.E, lodash.reduce(array, function(sum, x) {
139 return sum + Math.log(x);
140 }, 0) / array.length) || 0;
144 * Gets the Hz, i.e. operations per second, of `bench` adjusted for the
148 * @param {Object} bench The benchmark object.
149 * @returns {number} Returns the adjusted Hz.
151 function getHz(bench) {
152 var result = 1 / (bench.stats.mean + bench.stats.moe);
153 return isFinite(result) ? result : 0;
157 * Host objects can return type values that are different from their actual
158 * data type. The objects we are concerned with usually return non-primitive
159 * types of "object", "function", or "unknown".
162 * @param {*} object The owner of the property.
163 * @param {string} property The property to check.
164 * @returns {boolean} Returns `true` if the property value is a non-primitive, else `false`.
166 function isHostType(object, property) {
167 if (object == null) {
170 var type = typeof object[property];
171 return !rePrimitive.test(type) && (type != 'object' || !!object[property]);
175 * Logs text to the console.
178 * @param {string} text The text to log.
181 console.log(text + '');
183 // Scroll the Firebug Lite panel down.
184 fbPanel.scrollTop = fbPanel.scrollHeight;
189 * Runs all benchmark suites.
191 * @private (@public in the browser)
194 fbPanel = (fbPanel = root.document && document.getElementById('FirebugUI')) &&
195 (fbPanel = (fbPanel = fbPanel.contentWindow || fbPanel.contentDocument).document || fbPanel) &&
196 fbPanel.getElementById('fbPanel1');
198 log('\nSit back and relax, this may take a while.');
199 suites[0].run({ 'async': true });
202 /*--------------------------------------------------------------------------*/
204 lodash.extend(Benchmark.Suite.options, {
205 'onStart': function() {
206 log('\n' + this.name + ':');
208 'onCycle': function(event) {
211 'onComplete': function() {
212 for (var index = 0, length = this.length; index < length; index++) {
213 var bench = this[index];
219 log('There was a problem, skipping...');
222 var formatNumber = Benchmark.formatNumber,
223 fastest = this.filter('fastest'),
224 fastestHz = getHz(fastest[0]),
225 slowest = this.filter('slowest'),
226 slowestHz = getHz(slowest[0]),
227 aHz = getHz(this[0]),
228 bHz = getHz(this[1]);
230 if (fastest.length > 1) {
231 log('It\'s too close to call.');
232 aHz = bHz = slowestHz;
235 var percent = ((fastestHz / slowestHz) - 1) * 100;
238 fastest[0].name + ' is ' +
239 formatNumber(percent < 1 ? percent.toFixed(2) : Math.round(percent)) +
243 // Add score adjusted for margin of error.
247 // Remove current suite from queue.
252 suites[0].run({ 'async': true });
255 var aMeanHz = getGeometricMean(score.a),
256 bMeanHz = getGeometricMean(score.b),
257 fastestMeanHz = Math.max(aMeanHz, bMeanHz),
258 slowestMeanHz = Math.min(aMeanHz, bMeanHz),
259 xFaster = fastestMeanHz / slowestMeanHz,
260 percentFaster = formatNumber(Math.round((xFaster - 1) * 100)),
261 message = 'is ' + percentFaster + '% ' + (xFaster == 1 ? '' : '(' + formatNumber(xFaster.toFixed(2)) + 'x) ') + 'faster than';
264 if (aMeanHz >= bMeanHz) {
265 log('\n' + buildName + ' ' + message + ' ' + otherName + '.');
267 log('\n' + otherName + ' ' + message + ' ' + buildName + '.');
273 /*--------------------------------------------------------------------------*/
275 lodash.extend(Benchmark.options, {
278 var _ = global.underscore,\
279 lodash = global.lodash,\
280 belt = this.name == buildName ? lodash : _;\
282 var date = new Date,\
286 objects = Array(limit),\
287 numbers = Array(limit),\
288 fourNumbers = [5, 25, 10, 30],\
289 nestedNumbers = [1, [2], [3, [[4]]]],\
290 nestedObjects = [{}, [{}], [{}, [[{}]]]],\
291 twoNumbers = [12, 23];\
293 for (var index = 0; index < limit; index++) {\
294 numbers[index] = index;\
295 object["key" + index] = index;\
296 objects[index] = { "num": index };\
298 var strNumbers = numbers + "";\
300 if (typeof assign != "undefined") {\
301 var _assign = _.assign || _.extend,\
302 lodashAssign = lodash.assign;\
304 if (typeof bind != "undefined") {\
305 var thisArg = { "name": "fred" };\
307 var func = function(greeting, punctuation) {\
308 return (greeting || "hi") + " " + this.name + (punctuation || ".");\
311 var _boundNormal = _.bind(func, thisArg),\
312 _boundMultiple = _boundNormal,\
313 _boundPartial = _.bind(func, thisArg, "hi");\
315 var lodashBoundNormal = lodash.bind(func, thisArg),\
316 lodashBoundMultiple = lodashBoundNormal,\
317 lodashBoundPartial = lodash.bind(func, thisArg, "hi");\
319 for (index = 0; index < 10; index++) {\
320 _boundMultiple = _.bind(_boundMultiple, { "name": "fred" + index });\
321 lodashBoundMultiple = lodash.bind(lodashBoundMultiple, { "name": "fred" + index });\
324 if (typeof bindAll != "undefined") {\
325 var bindAllCount = -1,\
326 bindAllObjects = Array(this.count);\
328 var funcNames = belt.reject(belt.functions(belt).slice(0, 40), function(funcName) {\
329 return /^_/.test(funcName);\
332 // Potentially expensive.\n\
333 for (index = 0; index < this.count; index++) {\
334 bindAllObjects[index] = belt.reduce(funcNames, function(object, funcName) {\
335 object[funcName] = belt[funcName];\
340 if (typeof chaining != "undefined") {\
341 var even = function(v) { return v % 2 == 0; },\
342 square = function(v) { return v * v; };\
344 var largeArray = belt.range(10000),\
345 _chaining = _(largeArray).chain(),\
346 lodashChaining = lodash(largeArray).chain();\
348 if (typeof compact != "undefined") {\
349 var uncompacted = numbers.slice();\
350 uncompacted[2] = false;\
351 uncompacted[6] = null;\
352 uncompacted[18] = "";\
354 if (typeof flowRight != "undefined") {\
355 var compAddOne = function(n) { return n + 1; },\
356 compAddTwo = function(n) { return n + 2; },\
357 compAddThree = function(n) { return n + 3; };\
359 var _composed = _.flowRight && _.flowRight(compAddThree, compAddTwo, compAddOne),\
360 lodashComposed = lodash.flowRight && lodash.flowRight(compAddThree, compAddTwo, compAddOne);\
362 if (typeof countBy != "undefined" || typeof omit != "undefined") {\
363 var wordToNumber = {\
406 var words = belt.keys(wordToNumber).slice(0, limit);\
408 if (typeof flatten != "undefined") {\
409 var _flattenDeep = _.flatten([[1]])[0] !== 1,\
410 lodashFlattenDeep = lodash.flatten([[1]])[0] !== 1;\
412 if (typeof isEqual != "undefined") {\
413 var objectOfPrimitives = {\
419 var objectOfObjects = {\
420 "boolean": new Boolean(true),\
421 "number": new Number(1),\
422 "string": new String("a")\
425 var objectOfObjects2 = {\
426 "boolean": new Boolean(true),\
427 "number": new Number(1),\
428 "string": new String("A")\
433 objects2 = Array(limit),\
434 objects3 = Array(limit),\
435 numbers2 = Array(limit),\
436 numbers3 = Array(limit),\
437 nestedNumbers2 = [1, [2], [3, [[4]]]],\
438 nestedNumbers3 = [1, [2], [3, [[6]]]];\
440 for (index = 0; index < limit; index++) {\
441 object2["key" + index] = index;\
442 object3["key" + index] = index;\
443 objects2[index] = { "num": index };\
444 objects3[index] = { "num": index };\
445 numbers2[index] = index;\
446 numbers3[index] = index;\
448 object3["key" + (limit - 1)] = -1;\
449 objects3[limit - 1].num = -1;\
450 numbers3[limit - 1] = -1;\
452 if (typeof matches != "undefined") {\
453 var source = { "num": 9 };\
455 var _matcher = (_.matches || _.noop)(source),\
456 lodashMatcher = (lodash.matches || lodash.noop)(source);\
458 if (typeof multiArrays != "undefined") {\
459 var twentyValues = belt.shuffle(belt.range(20)),\
460 fortyValues = belt.shuffle(belt.range(40)),\
461 hundredSortedValues = belt.range(100),\
462 hundredValues = belt.shuffle(hundredSortedValues),\
463 hundredValues2 = belt.shuffle(hundredValues),\
464 hundredTwentyValues = belt.shuffle(belt.range(120)),\
465 hundredTwentyValues2 = belt.shuffle(hundredTwentyValues),\
466 twoHundredValues = belt.shuffle(belt.range(200)),\
467 twoHundredValues2 = belt.shuffle(twoHundredValues);\
469 if (typeof partial != "undefined") {\
470 var func = function(greeting, punctuation) {\
471 return greeting + " fred" + (punctuation || ".");\
474 var _partial = _.partial(func, "hi"),\
475 lodashPartial = lodash.partial(func, "hi");\
477 if (typeof template != "undefined") {\
479 "header1": "Header1",\
480 "header2": "Header2",\
481 "header3": "Header3",\
482 "header4": "Header4",\
483 "header5": "Header5",\
484 "header6": "Header6",\
485 "list": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]\
490 "<h1 class=\'header1\'><%= header1 %></h1>" +\
491 "<h2 class=\'header2\'><%= header2 %></h2>" +\
492 "<h3 class=\'header3\'><%= header3 %></h3>" +\
493 "<h4 class=\'header4\'><%= header4 %></h4>" +\
494 "<h5 class=\'header5\'><%= header5 %></h5>" +\
495 "<h6 class=\'header6\'><%= header6 %></h6>" +\
496 "<ul class=\'list\'>" +\
497 "<% for (var index = 0, length = list.length; index < length; index++) { %>" +\
498 "<li class=\'item\'><%= list[index] %></li>" +\
505 "<h1 class=\'header1\'><%= data.header1 %></h1>" +\
506 "<h2 class=\'header2\'><%= data.header2 %></h2>" +\
507 "<h3 class=\'header3\'><%= data.header3 %></h3>" +\
508 "<h4 class=\'header4\'><%= data.header4 %></h4>" +\
509 "<h5 class=\'header5\'><%= data.header5 %></h5>" +\
510 "<h6 class=\'header6\'><%= data.header6 %></h6>" +\
511 "<ul class=\'list\'>" +\
512 "<% for (var index = 0, length = data.list.length; index < length; index++) { %>" +\
513 "<li class=\'item\'><%= data.list[index] %></li>" +\
518 var settingsObject = { "variable": "data" };\
520 var _tpl = _.template(tpl),\
521 _tplVerbose = _.template(tplVerbose, null, settingsObject);\
523 var lodashTpl = lodash.template(tpl),\
524 lodashTplVerbose = lodash.template(tplVerbose, null, settingsObject);\
526 if (typeof wrap != "undefined") {\
527 var add = function(a, b) {\
531 var average = function(func, a, b) {\
532 return (func(a, b) / 2).toFixed(2);\
535 var _wrapped = _.wrap(add, average);\
536 lodashWrapped = lodash.wrap(add, average);\
538 if (typeof zip != "undefined") {\
539 var unzipped = [["a", "b", "c"], [1, 2, 3], [true, false, true]];\
543 /*--------------------------------------------------------------------------*/
546 Benchmark.Suite('`_(...).map(...).filter(...).take(...).value()`')
548 'fn': 'lodashChaining.map(square).filter(even).take(100).value()',
549 'teardown': 'function chaining(){}'
552 'fn': '_chaining.map(square).filter(even).take(100).value()',
553 'teardown': 'function chaining(){}'
557 /*--------------------------------------------------------------------------*/
560 Benchmark.Suite('`_.assign`')
562 'fn': 'lodashAssign({}, { "a": 1, "b": 2, "c": 3 })',
563 'teardown': 'function assign(){}'
566 'fn': '_assign({}, { "a": 1, "b": 2, "c": 3 })',
567 'teardown': 'function assign(){}'
572 Benchmark.Suite('`_.assign` with multiple sources')
574 'fn': 'lodashAssign({}, { "a": 1, "b": 2 }, { "c": 3, "d": 4 })',
575 'teardown': 'function assign(){}'
578 'fn': '_assign({}, { "a": 1, "b": 2 }, { "c": 3, "d": 4 })',
579 'teardown': 'function assign(){}'
583 /*--------------------------------------------------------------------------*/
586 Benchmark.Suite('`_.bind` (slow path)')
588 'fn': 'lodash.bind(function() { return this.name; }, { "name": "fred" })',
589 'teardown': 'function bind(){}'
592 'fn': '_.bind(function() { return this.name; }, { "name": "fred" })',
593 'teardown': 'function bind(){}'
598 Benchmark.Suite('bound call with arguments')
600 'fn': 'lodashBoundNormal("hi", "!")',
601 'teardown': 'function bind(){}'
604 'fn': '_boundNormal("hi", "!")',
605 'teardown': 'function bind(){}'
610 Benchmark.Suite('bound and partially applied call with arguments')
612 'fn': 'lodashBoundPartial("!")',
613 'teardown': 'function bind(){}'
616 'fn': '_boundPartial("!")',
617 'teardown': 'function bind(){}'
622 Benchmark.Suite('bound multiple times')
624 'fn': 'lodashBoundMultiple()',
625 'teardown': 'function bind(){}'
628 'fn': '_boundMultiple()',
629 'teardown': 'function bind(){}'
633 /*--------------------------------------------------------------------------*/
636 Benchmark.Suite('`_.bindAll`')
638 'fn': 'lodash.bindAll(bindAllObjects[++bindAllCount], funcNames)',
639 'teardown': 'function bindAll(){}'
642 'fn': '_.bindAll(bindAllObjects[++bindAllCount], funcNames)',
643 'teardown': 'function bindAll(){}'
647 /*--------------------------------------------------------------------------*/
650 Benchmark.Suite('`_.clone` with an array')
652 lodash.clone(numbers)'
660 Benchmark.Suite('`_.clone` with an object')
662 lodash.clone(object)'
669 /*--------------------------------------------------------------------------*/
672 Benchmark.Suite('`_.compact`')
674 'fn': 'lodash.compact(uncompacted)',
675 'teardown': 'function compact(){}'
678 'fn': '_.compact(uncompacted)',
679 'teardown': 'function compact(){}'
683 /*--------------------------------------------------------------------------*/
686 Benchmark.Suite('`_.countBy` with `callback` iterating an array')
688 lodash.countBy(numbers, function(num) { return num >> 1; })'
691 _.countBy(numbers, function(num) { return num >> 1; })'
696 Benchmark.Suite('`_.countBy` with `property` name iterating an array')
698 'fn': 'lodash.countBy(words, "length")',
699 'teardown': 'function countBy(){}'
702 'fn': '_.countBy(words, "length")',
703 'teardown': 'function countBy(){}'
708 Benchmark.Suite('`_.countBy` with `callback` iterating an object')
710 'fn': 'lodash.countBy(wordToNumber, function(num) { return num >> 1; })',
711 'teardown': 'function countBy(){}'
714 'fn': '_.countBy(wordToNumber, function(num) { return num >> 1; })',
715 'teardown': 'function countBy(){}'
719 /*--------------------------------------------------------------------------*/
722 Benchmark.Suite('`_.defaults`')
724 lodash.defaults({ "key2": 2, "key6": 6, "key18": 18 }, object)'
727 _.defaults({ "key2": 2, "key6": 6, "key18": 18 }, object)'
731 /*--------------------------------------------------------------------------*/
734 Benchmark.Suite('`_.difference`')
736 lodash.difference(numbers, twoNumbers, fourNumbers)'
739 _.difference(numbers, twoNumbers, fourNumbers)'
744 Benchmark.Suite('`_.difference` iterating 20 and 40 elements')
746 'fn': 'lodash.difference(twentyValues, fortyValues)',
747 'teardown': 'function multiArrays(){}'
750 'fn': '_.difference(twentyValues, fortyValues)',
751 'teardown': 'function multiArrays(){}'
756 Benchmark.Suite('`_.difference` iterating 200 elements')
758 'fn': 'lodash.difference(twoHundredValues, twoHundredValues2)',
759 'teardown': 'function multiArrays(){}'
762 'fn': '_.difference(twoHundredValues, twoHundredValues2)',
763 'teardown': 'function multiArrays(){}'
767 /*--------------------------------------------------------------------------*/
770 Benchmark.Suite('`_.each` iterating an array')
773 lodash.each(numbers, function(num) {\
774 result.push(num * 2);\
779 _.each(numbers, function(num) {\
780 result.push(num * 2);\
786 Benchmark.Suite('`_.each` iterating an object')
789 lodash.each(object, function(num) {\
790 result.push(num * 2);\
795 _.each(object, function(num) {\
796 result.push(num * 2);\
801 /*--------------------------------------------------------------------------*/
804 Benchmark.Suite('`_.every` iterating an array')
806 lodash.every(numbers, function(num) {\
811 _.every(numbers, function(num) {\
818 Benchmark.Suite('`_.every` iterating an object')
820 lodash.every(object, function(num) {\
825 _.every(object, function(num) {\
831 /*--------------------------------------------------------------------------*/
834 Benchmark.Suite('`_.filter` iterating an array')
836 lodash.filter(numbers, function(num) {\
841 _.filter(numbers, function(num) {\
848 Benchmark.Suite('`_.filter` iterating an object')
850 lodash.filter(object, function(num) {\
855 _.filter(object, function(num) {\
862 Benchmark.Suite('`_.filter` with `_.matches` shorthand')
864 'fn': 'lodash.filter(objects, source)',
865 'teardown': 'function matches(){}'
868 'fn': '_.filter(objects, source)',
869 'teardown': 'function matches(){}'
874 Benchmark.Suite('`_.filter` with `_.matches` predicate')
876 'fn': 'lodash.filter(objects, lodashMatcher)',
877 'teardown': 'function matches(){}'
880 'fn': '_.filter(objects, _matcher)',
881 'teardown': 'function matches(){}'
885 /*--------------------------------------------------------------------------*/
888 Benchmark.Suite('`_.find` iterating an array')
890 lodash.find(numbers, function(num) {\
891 return num === (limit - 1);\
895 _.find(numbers, function(num) {\
896 return num === (limit - 1);\
902 Benchmark.Suite('`_.find` iterating an object')
904 lodash.find(object, function(value, key) {\
905 return /\D9$/.test(key);\
909 _.find(object, function(value, key) {\
910 return /\D9$/.test(key);\
915 // Avoid Underscore induced `OutOfMemoryError` in Rhino and Ringo.
917 Benchmark.Suite('`_.find` with `_.matches` shorthand')
919 'fn': 'lodash.find(objects, source)',
920 'teardown': 'function matches(){}'
923 'fn': '_.find(objects, source)',
924 'teardown': 'function matches(){}'
928 /*--------------------------------------------------------------------------*/
931 Benchmark.Suite('`_.flatten`')
933 'fn': 'lodash.flatten(nestedNumbers, !lodashFlattenDeep)',
934 'teardown': 'function flatten(){}'
937 'fn': '_.flatten(nestedNumbers, !_flattenDeep)',
938 'teardown': 'function flatten(){}'
942 /*--------------------------------------------------------------------------*/
945 Benchmark.Suite('`_.flattenDeep` nested arrays of numbers')
947 'fn': 'lodash.flattenDeep(nestedNumbers)',
948 'teardown': 'function flatten(){}'
951 'fn': '_.flattenDeep(nestedNumbers)',
952 'teardown': 'function flatten(){}'
957 Benchmark.Suite('`_.flattenDeep` nest arrays of objects')
959 'fn': 'lodash.flattenDeep(nestedObjects)',
960 'teardown': 'function flatten(){}'
963 'fn': '_.flattenDeep(nestedObjects)',
964 'teardown': 'function flatten(){}'
968 /*--------------------------------------------------------------------------*/
971 Benchmark.Suite('`_.flowRight`')
973 'fn': 'lodash.flowRight(compAddThree, compAddTwo, compAddOne)',
974 'teardown': 'function flowRight(){}'
977 'fn': '_.flowRight(compAddThree, compAddTwo, compAddOne)',
978 'teardown': 'function flowRight(){}'
983 Benchmark.Suite('composed call')
985 'fn': 'lodashComposed(0)',
986 'teardown': 'function flowRight(){}'
989 'fn': '_composed(0)',
990 'teardown': 'function flowRight(){}'
994 /*--------------------------------------------------------------------------*/
997 Benchmark.Suite('`_.functions`')
999 lodash.functions(lodash)'
1002 _.functions(lodash)'
1006 /*--------------------------------------------------------------------------*/
1009 Benchmark.Suite('`_.groupBy` with `callback` iterating an array')
1011 lodash.groupBy(numbers, function(num) { return num >> 1; })'
1014 _.groupBy(numbers, function(num) { return num >> 1; })'
1019 Benchmark.Suite('`_.groupBy` with `property` name iterating an array')
1021 'fn': 'lodash.groupBy(words, "length")',
1022 'teardown': 'function countBy(){}'
1025 'fn': '_.groupBy(words, "length")',
1026 'teardown': 'function countBy(){}'
1031 Benchmark.Suite('`_.groupBy` with `callback` iterating an object')
1033 'fn': 'lodash.groupBy(wordToNumber, function(num) { return num >> 1; })',
1034 'teardown': 'function countBy(){}'
1037 'fn': '_.groupBy(wordToNumber, function(num) { return num >> 1; })',
1038 'teardown': 'function countBy(){}'
1042 /*--------------------------------------------------------------------------*/
1045 Benchmark.Suite('`_.includes` searching an array')
1047 lodash.includes(numbers, limit - 1)'
1050 _.includes(numbers, limit - 1)'
1055 Benchmark.Suite('`_.includes` searching an object')
1057 lodash.includes(object, limit - 1)'
1060 _.includes(object, limit - 1)'
1064 if (lodash.includes('ab', 'ab') && _.includes('ab', 'ab')) {
1066 Benchmark.Suite('`_.includes` searching a string')
1068 lodash.includes(strNumbers, "," + (limit - 1))'
1071 _.includes(strNumbers, "," + (limit - 1))'
1076 /*--------------------------------------------------------------------------*/
1079 Benchmark.Suite('`_.indexOf`')
1081 'fn': 'lodash.indexOf(hundredSortedValues, 99)',
1082 'teardown': 'function multiArrays(){}'
1085 'fn': '_.indexOf(hundredSortedValues, 99)',
1086 'teardown': 'function multiArrays(){}'
1090 /*--------------------------------------------------------------------------*/
1093 Benchmark.Suite('`_.intersection`')
1095 lodash.intersection(numbers, twoNumbers, fourNumbers)'
1098 _.intersection(numbers, twoNumbers, fourNumbers)'
1103 Benchmark.Suite('`_.intersection` iterating 120 elements')
1105 'fn': 'lodash.intersection(hundredTwentyValues, hundredTwentyValues2)',
1106 'teardown': 'function multiArrays(){}'
1109 'fn': '_.intersection(hundredTwentyValues, hundredTwentyValues2)',
1110 'teardown': 'function multiArrays(){}'
1114 /*--------------------------------------------------------------------------*/
1117 Benchmark.Suite('`_.invert`')
1119 lodash.invert(object)'
1126 /*--------------------------------------------------------------------------*/
1129 Benchmark.Suite('`_.invokeMap` iterating an array')
1131 lodash.invokeMap(numbers, "toFixed")'
1134 _.invokeMap(numbers, "toFixed")'
1139 Benchmark.Suite('`_.invokeMap` with arguments iterating an array')
1141 lodash.invokeMap(numbers, "toFixed", 1)'
1144 _.invokeMap(numbers, "toFixed", 1)'
1149 Benchmark.Suite('`_.invokeMap` with a function for `path` iterating an array')
1151 lodash.invokeMap(numbers, Number.prototype.toFixed, 1)'
1154 _.invokeMap(numbers, Number.prototype.toFixed, 1)'
1159 Benchmark.Suite('`_.invokeMap` iterating an object')
1161 lodash.invokeMap(object, "toFixed", 1)'
1164 _.invokeMap(object, "toFixed", 1)'
1168 /*--------------------------------------------------------------------------*/
1171 Benchmark.Suite('`_.isEqual` comparing primitives')
1174 lodash.isEqual(1, "1");\
1175 lodash.isEqual(1, 1)',
1176 'teardown': 'function isEqual(){}'
1182 'teardown': 'function isEqual(){}'
1187 Benchmark.Suite('`_.isEqual` comparing primitives and their object counterparts (edge case)')
1190 lodash.isEqual(objectOfPrimitives, objectOfObjects);\
1191 lodash.isEqual(objectOfPrimitives, objectOfObjects2)',
1192 'teardown': 'function isEqual(){}'
1196 _.isEqual(objectOfPrimitives, objectOfObjects);\
1197 _.isEqual(objectOfPrimitives, objectOfObjects2)',
1198 'teardown': 'function isEqual(){}'
1203 Benchmark.Suite('`_.isEqual` comparing arrays')
1206 lodash.isEqual(numbers, numbers2);\
1207 lodash.isEqual(numbers2, numbers3)',
1208 'teardown': 'function isEqual(){}'
1212 _.isEqual(numbers, numbers2);\
1213 _.isEqual(numbers2, numbers3)',
1214 'teardown': 'function isEqual(){}'
1219 Benchmark.Suite('`_.isEqual` comparing nested arrays')
1222 lodash.isEqual(nestedNumbers, nestedNumbers2);\
1223 lodash.isEqual(nestedNumbers2, nestedNumbers3)',
1224 'teardown': 'function isEqual(){}'
1228 _.isEqual(nestedNumbers, nestedNumbers2);\
1229 _.isEqual(nestedNumbers2, nestedNumbers3)',
1230 'teardown': 'function isEqual(){}'
1235 Benchmark.Suite('`_.isEqual` comparing arrays of objects')
1238 lodash.isEqual(objects, objects2);\
1239 lodash.isEqual(objects2, objects3)',
1240 'teardown': 'function isEqual(){}'
1244 _.isEqual(objects, objects2);\
1245 _.isEqual(objects2, objects3)',
1246 'teardown': 'function isEqual(){}'
1251 Benchmark.Suite('`_.isEqual` comparing objects')
1254 lodash.isEqual(object, object2);\
1255 lodash.isEqual(object2, object3)',
1256 'teardown': 'function isEqual(){}'
1260 _.isEqual(object, object2);\
1261 _.isEqual(object2, object3)',
1262 'teardown': 'function isEqual(){}'
1266 /*--------------------------------------------------------------------------*/
1269 Benchmark.Suite('`_.isArguments`, `_.isDate`, `_.isFunction`, `_.isNumber`, `_.isObject`, `_.isRegExp`')
1271 lodash.isArguments(arguments);\
1272 lodash.isArguments(object);\
1273 lodash.isDate(date);\
1274 lodash.isDate(object);\
1275 lodash.isFunction(lodash);\
1276 lodash.isFunction(object);\
1277 lodash.isNumber(1);\
1278 lodash.isNumber(object);\
1279 lodash.isObject(object);\
1280 lodash.isObject(1);\
1281 lodash.isRegExp(regexp);\
1282 lodash.isRegExp(object)'
1285 _.isArguments(arguments);\
1286 _.isArguments(object);\
1290 _.isFunction(object);\
1292 _.isNumber(object);\
1293 _.isObject(object);\
1295 _.isRegExp(regexp);\
1300 /*--------------------------------------------------------------------------*/
1303 Benchmark.Suite('`_.keys` (uses native `Object.keys` if available)')
1305 lodash.keys(object)'
1312 /*--------------------------------------------------------------------------*/
1315 Benchmark.Suite('`_.lastIndexOf`')
1317 'fn': 'lodash.lastIndexOf(hundredSortedValues, 0)',
1318 'teardown': 'function multiArrays(){}'
1321 'fn': '_.lastIndexOf(hundredSortedValues, 0)',
1322 'teardown': 'function multiArrays(){}'
1326 /*--------------------------------------------------------------------------*/
1329 Benchmark.Suite('`_.map` iterating an array')
1331 lodash.map(objects, function(value) {\
1336 _.map(objects, function(value) {\
1343 Benchmark.Suite('`_.map` iterating an object')
1345 lodash.map(object, function(value) {\
1350 _.map(object, function(value) {\
1357 Benchmark.Suite('`_.map` with `_.property` shorthand')
1359 lodash.map(objects, "num")'
1362 _.map(objects, "num")'
1366 /*--------------------------------------------------------------------------*/
1369 Benchmark.Suite('`_.max`')
1371 lodash.max(numbers)'
1378 /*--------------------------------------------------------------------------*/
1381 Benchmark.Suite('`_.min`')
1383 lodash.min(numbers)'
1390 /*--------------------------------------------------------------------------*/
1393 Benchmark.Suite('`_.omit` iterating 20 properties, omitting 2 keys')
1395 lodash.omit(object, "key6", "key13")'
1398 _.omit(object, "key6", "key13")'
1403 Benchmark.Suite('`_.omit` iterating 40 properties, omitting 20 keys')
1405 'fn': 'lodash.omit(wordToNumber, words)',
1406 'teardown': 'function omit(){}'
1409 'fn': '_.omit(wordToNumber, words)',
1410 'teardown': 'function omit(){}'
1414 /*--------------------------------------------------------------------------*/
1417 Benchmark.Suite('`_.partial` (slow path)')
1419 'fn': 'lodash.partial(function(greeting) { return greeting + " " + this.name; }, "hi")',
1420 'teardown': 'function partial(){}'
1423 'fn': '_.partial(function(greeting) { return greeting + " " + this.name; }, "hi")',
1424 'teardown': 'function partial(){}'
1429 Benchmark.Suite('partially applied call with arguments')
1431 'fn': 'lodashPartial("!")',
1432 'teardown': 'function partial(){}'
1435 'fn': '_partial("!")',
1436 'teardown': 'function partial(){}'
1440 /*--------------------------------------------------------------------------*/
1443 Benchmark.Suite('`_.partition` iterating an array')
1445 lodash.partition(numbers, function(num) {\
1450 _.partition(numbers, function(num) {\
1457 Benchmark.Suite('`_.partition` iterating an object')
1459 lodash.partition(object, function(num) {\
1464 _.partition(object, function(num) {\
1470 /*--------------------------------------------------------------------------*/
1473 Benchmark.Suite('`_.pick`')
1475 lodash.pick(object, "key6", "key13")'
1478 _.pick(object, "key6", "key13")'
1482 /*--------------------------------------------------------------------------*/
1485 Benchmark.Suite('`_.reduce` iterating an array')
1487 lodash.reduce(numbers, function(result, value, index) {\
1488 result[index] = value;\
1493 _.reduce(numbers, function(result, value, index) {\
1494 result[index] = value;\
1501 Benchmark.Suite('`_.reduce` iterating an object')
1503 lodash.reduce(object, function(result, value, key) {\
1504 result.push(key, value);\
1509 _.reduce(object, function(result, value, key) {\
1510 result.push(key, value);\
1516 /*--------------------------------------------------------------------------*/
1519 Benchmark.Suite('`_.reduceRight` iterating an array')
1521 lodash.reduceRight(numbers, function(result, value, index) {\
1522 result[index] = value;\
1527 _.reduceRight(numbers, function(result, value, index) {\
1528 result[index] = value;\
1535 Benchmark.Suite('`_.reduceRight` iterating an object')
1537 lodash.reduceRight(object, function(result, value, key) {\
1538 result.push(key, value);\
1543 _.reduceRight(object, function(result, value, key) {\
1544 result.push(key, value);\
1550 /*--------------------------------------------------------------------------*/
1553 Benchmark.Suite('`_.reject` iterating an array')
1555 lodash.reject(numbers, function(num) {\
1560 _.reject(numbers, function(num) {\
1567 Benchmark.Suite('`_.reject` iterating an object')
1569 lodash.reject(object, function(num) {\
1574 _.reject(object, function(num) {\
1580 /*--------------------------------------------------------------------------*/
1583 Benchmark.Suite('`_.sampleSize`')
1585 lodash.sampleSize(numbers, limit / 2)'
1588 _.sampleSize(numbers, limit / 2)'
1592 /*--------------------------------------------------------------------------*/
1595 Benchmark.Suite('`_.shuffle`')
1597 lodash.shuffle(numbers)'
1604 /*--------------------------------------------------------------------------*/
1607 Benchmark.Suite('`_.size` with an object')
1609 lodash.size(object)'
1616 /*--------------------------------------------------------------------------*/
1619 Benchmark.Suite('`_.some` iterating an array')
1621 lodash.some(numbers, function(num) {\
1622 return num == (limit - 1);\
1626 _.some(numbers, function(num) {\
1627 return num == (limit - 1);\
1633 Benchmark.Suite('`_.some` iterating an object')
1635 lodash.some(object, function(num) {\
1636 return num == (limit - 1);\
1640 _.some(object, function(num) {\
1641 return num == (limit - 1);\
1646 /*--------------------------------------------------------------------------*/
1649 Benchmark.Suite('`_.sortBy` with `callback`')
1651 lodash.sortBy(numbers, function(num) { return Math.sin(num); })'
1654 _.sortBy(numbers, function(num) { return Math.sin(num); })'
1659 Benchmark.Suite('`_.sortBy` with `property` name')
1661 'fn': 'lodash.sortBy(words, "length")',
1662 'teardown': 'function countBy(){}'
1665 'fn': '_.sortBy(words, "length")',
1666 'teardown': 'function countBy(){}'
1670 /*--------------------------------------------------------------------------*/
1673 Benchmark.Suite('`_.sortedIndex`')
1675 lodash.sortedIndex(numbers, limit)'
1678 _.sortedIndex(numbers, limit)'
1682 /*--------------------------------------------------------------------------*/
1685 Benchmark.Suite('`_.sortedIndexBy`')
1688 lodash.sortedIndexBy(words, "twenty-five", function(value) {\
1689 return wordToNumber[value];\
1691 'teardown': 'function countBy(){}'
1695 _.sortedIndexBy(words, "twenty-five", function(value) {\
1696 return wordToNumber[value];\
1698 'teardown': 'function countBy(){}'
1702 /*--------------------------------------------------------------------------*/
1705 Benchmark.Suite('`_.sortedIndexOf`')
1707 'fn': 'lodash.sortedIndexOf(hundredSortedValues, 99)',
1708 'teardown': 'function multiArrays(){}'
1711 'fn': '_.sortedIndexOf(hundredSortedValues, 99)',
1712 'teardown': 'function multiArrays(){}'
1716 /*--------------------------------------------------------------------------*/
1719 Benchmark.Suite('`_.sortedLastIndexOf`')
1721 'fn': 'lodash.sortedLastIndexOf(hundredSortedValues, 0)',
1722 'teardown': 'function multiArrays(){}'
1725 'fn': '_.sortedLastIndexOf(hundredSortedValues, 0)',
1726 'teardown': 'function multiArrays(){}'
1730 /*--------------------------------------------------------------------------*/
1733 Benchmark.Suite('`_.sum`')
1735 lodash.sum(numbers)'
1742 /*--------------------------------------------------------------------------*/
1745 Benchmark.Suite('`_.template` (slow path)')
1747 'fn': 'lodash.template(tpl)(tplData)',
1748 'teardown': 'function template(){}'
1751 'fn': '_.template(tpl)(tplData)',
1752 'teardown': 'function template(){}'
1757 Benchmark.Suite('compiled template')
1759 'fn': 'lodashTpl(tplData)',
1760 'teardown': 'function template(){}'
1763 'fn': '_tpl(tplData)',
1764 'teardown': 'function template(){}'
1769 Benchmark.Suite('compiled template without a with-statement')
1771 'fn': 'lodashTplVerbose(tplData)',
1772 'teardown': 'function template(){}'
1775 'fn': '_tplVerbose(tplData)',
1776 'teardown': 'function template(){}'
1780 /*--------------------------------------------------------------------------*/
1783 Benchmark.Suite('`_.times`')
1786 lodash.times(limit, function(n) { result.push(n); })'
1790 _.times(limit, function(n) { result.push(n); })'
1794 /*--------------------------------------------------------------------------*/
1797 Benchmark.Suite('`_.toArray` with an array (edge case)')
1799 lodash.toArray(numbers)'
1807 Benchmark.Suite('`_.toArray` with an object')
1809 lodash.toArray(object)'
1816 /*--------------------------------------------------------------------------*/
1819 Benchmark.Suite('`_.toPairs`')
1821 lodash.toPairs(object)'
1828 /*--------------------------------------------------------------------------*/
1831 Benchmark.Suite('`_.unescape` string without html entities')
1833 lodash.unescape("`&`, `<`, `>`, `\\"`, and `\'`")'
1836 _.unescape("`&`, `<`, `>`, `\\"`, and `\'`")'
1841 Benchmark.Suite('`_.unescape` string with html entities')
1843 lodash.unescape("`&`, `<`, `>`, `"`, and `'`")'
1846 _.unescape("`&`, `<`, `>`, `"`, and `'`")'
1850 /*--------------------------------------------------------------------------*/
1853 Benchmark.Suite('`_.union`')
1855 lodash.union(numbers, twoNumbers, fourNumbers)'
1858 _.union(numbers, twoNumbers, fourNumbers)'
1863 Benchmark.Suite('`_.union` iterating an array of 200 elements')
1865 'fn': 'lodash.union(hundredValues, hundredValues2)',
1866 'teardown': 'function multiArrays(){}'
1869 'fn': '_.union(hundredValues, hundredValues2)',
1870 'teardown': 'function multiArrays(){}'
1874 /*--------------------------------------------------------------------------*/
1877 Benchmark.Suite('`_.uniq`')
1879 lodash.uniq(numbers.concat(twoNumbers, fourNumbers))'
1882 _.uniq(numbers.concat(twoNumbers, fourNumbers))'
1887 Benchmark.Suite('`_.uniq` iterating an array of 200 elements')
1889 'fn': 'lodash.uniq(twoHundredValues)',
1890 'teardown': 'function multiArrays(){}'
1893 'fn': '_.uniq(twoHundredValues)',
1894 'teardown': 'function multiArrays(){}'
1898 /*--------------------------------------------------------------------------*/
1901 Benchmark.Suite('`_.uniqBy`')
1903 lodash.uniqBy(numbers.concat(twoNumbers, fourNumbers), function(num) {\
1908 _.uniqBy(numbers.concat(twoNumbers, fourNumbers), function(num) {\
1914 /*--------------------------------------------------------------------------*/
1917 Benchmark.Suite('`_.values`')
1919 lodash.values(object)'
1926 /*--------------------------------------------------------------------------*/
1929 Benchmark.Suite('`_.without`')
1931 lodash.without(numbers, 9, 12, 14, 15)'
1934 _.without(numbers, 9, 12, 14, 15)'
1938 /*--------------------------------------------------------------------------*/
1941 Benchmark.Suite('`_.wrap` result called')
1943 'fn': 'lodashWrapped(2, 5)',
1944 'teardown': 'function wrap(){}'
1947 'fn': '_wrapped(2, 5)',
1948 'teardown': 'function wrap(){}'
1952 /*--------------------------------------------------------------------------*/
1955 Benchmark.Suite('`_.zip`')
1957 'fn': 'lodash.zip.apply(lodash, unzipped)',
1958 'teardown': 'function zip(){}'
1961 'fn': '_.zip.apply(_, unzipped)',
1962 'teardown': 'function zip(){}'
1966 /*--------------------------------------------------------------------------*/
1968 if (Benchmark.platform + '') {
1969 log(Benchmark.platform);
1971 // Expose `run` to be called later when executing in a browser.