blob: baee142b92f1dde347bce37ccddab980f9d49ca8 [file] [log] [blame]
Matteo Scandolo280dcd32016-05-16 09:59:38 -07001;(function() {
2
3 /** Used to access the Firebug Lite panel (set by `run`). */
4 var fbPanel;
5
6 /** Used as a safe reference for `undefined` in pre ES5 environments. */
7 var undefined;
8
9 /** Used as a reference to the global object. */
10 var root = typeof global == 'object' && global || this;
11
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,
17 noop = function() {},
18 params = root.arguments,
19 system = root.system;
20
21 /** Add `console.log()` support for Rhino and RingoJS. */
22 var console = root.console || (root.console = { 'log': root.print });
23
24 /** The file path of the lodash file to test. */
25 var filePath = (function() {
26 var min = 0,
27 result = [];
28
29 if (phantom) {
30 result = params = phantom.args;
31 } else if (system) {
32 min = 1;
33 result = params = system.args;
34 } else if (argv) {
35 min = 2;
36 result = params = argv;
37 } else if (params) {
38 result = params;
39 }
40 var last = result[result.length - 1];
41 result = (result.length > min && !/perf(?:\.js)?$/.test(last)) ? last : '../lodash.js';
42
43 if (!amd) {
44 try {
45 result = require('fs').realpathSync(result);
46 } catch (e) {}
47
48 try {
49 result = require.resolve(result);
50 } catch (e) {}
51 }
52 return result;
53 }());
54
55 /** Used to match path separators. */
56 var rePathSeparator = /[\/\\]/;
57
58 /** Used to detect primitive types. */
59 var rePrimitive = /^(?:boolean|number|string|undefined)$/;
60
61 /** Used to match RegExp special characters. */
62 var reSpecialChars = /[.*+?^=!:${}()|[\]\/\\]/g;
63
64 /** The `ui` object. */
65 var ui = root.ui || (root.ui = {
66 'buildPath': basename(filePath, '.js'),
67 'otherPath': 'underscore'
68 });
69
70 /** The lodash build basename. */
71 var buildName = root.buildName = basename(ui.buildPath, '.js');
72
73 /** The other library basename. */
74 var otherName = root.otherName = (function() {
75 var result = basename(ui.otherPath, '.js');
76 return result + (result == buildName ? ' (2)' : '');
77 }());
78
79 /** Used to score performance. */
80 var score = { 'a': [], 'b': [] };
81
82 /** Used to queue benchmark suites. */
83 var suites = [];
84
85 /** Use a single "load" function. */
86 var load = (typeof require == 'function' && !amd)
87 ? require
88 : noop;
89
90 /** Load lodash. */
91 var lodash = root.lodash || (root.lodash = (
92 lodash = load(filePath) || root._,
93 lodash = lodash._ || lodash,
94 (lodash.runInContext ? lodash.runInContext(root) : lodash),
95 lodash.noConflict()
96 ));
97
98 /** Load Underscore. */
99 var _ = root.underscore || (root.underscore = (
100 _ = load('../vendor/underscore/underscore.js') || root._,
101 _._ || _
102 ));
103
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 }))
109 ));
110
111 /*--------------------------------------------------------------------------*/
112
113 /**
114 * Gets the basename of the given `filePath`. If the file `extension` is passed,
115 * it will be removed from the basename.
116 *
117 * @private
118 * @param {string} path The file path to inspect.
119 * @param {string} extension The extension to remove.
120 * @returns {string} Returns the basename.
121 */
122 function basename(filePath, extension) {
123 var result = (filePath || '').split(rePathSeparator).pop();
124 return (arguments.length < 2)
125 ? result
126 : result.replace(RegExp(extension.replace(reSpecialChars, '\\$&') + '$'), '');
127 }
128
129 /**
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.
132 *
133 * @private
134 * @param {Array} array The array of values.
135 * @returns {number} The geometric mean.
136 */
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;
141 }
142
143 /**
144 * Gets the Hz, i.e. operations per second, of `bench` adjusted for the
145 * margin of error.
146 *
147 * @private
148 * @param {Object} bench The benchmark object.
149 * @returns {number} Returns the adjusted Hz.
150 */
151 function getHz(bench) {
152 var result = 1 / (bench.stats.mean + bench.stats.moe);
153 return isFinite(result) ? result : 0;
154 }
155
156 /**
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".
160 *
161 * @private
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`.
165 */
166 function isHostType(object, property) {
167 if (object == null) {
168 return false;
169 }
170 var type = typeof object[property];
171 return !rePrimitive.test(type) && (type != 'object' || !!object[property]);
172 }
173
174 /**
175 * Logs text to the console.
176 *
177 * @private
178 * @param {string} text The text to log.
179 */
180 function log(text) {
181 console.log(text + '');
182 if (fbPanel) {
183 // Scroll the Firebug Lite panel down.
184 fbPanel.scrollTop = fbPanel.scrollHeight;
185 }
186 }
187
188 /**
189 * Runs all benchmark suites.
190 *
191 * @private (@public in the browser)
192 */
193 function run() {
194 fbPanel = (fbPanel = root.document && document.getElementById('FirebugUI')) &&
195 (fbPanel = (fbPanel = fbPanel.contentWindow || fbPanel.contentDocument).document || fbPanel) &&
196 fbPanel.getElementById('fbPanel1');
197
198 log('\nSit back and relax, this may take a while.');
199 suites[0].run({ 'async': true });
200 }
201
202 /*--------------------------------------------------------------------------*/
203
204 lodash.extend(Benchmark.Suite.options, {
205 'onStart': function() {
206 log('\n' + this.name + ':');
207 },
208 'onCycle': function(event) {
209 log(event.target);
210 },
211 'onComplete': function() {
212 for (var index = 0, length = this.length; index < length; index++) {
213 var bench = this[index];
214 if (bench.error) {
215 var errored = true;
216 }
217 }
218 if (errored) {
219 log('There was a problem, skipping...');
220 }
221 else {
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]);
229
230 if (fastest.length > 1) {
231 log('It\'s too close to call.');
232 aHz = bHz = slowestHz;
233 }
234 else {
235 var percent = ((fastestHz / slowestHz) - 1) * 100;
236
237 log(
238 fastest[0].name + ' is ' +
239 formatNumber(percent < 1 ? percent.toFixed(2) : Math.round(percent)) +
240 '% faster.'
241 );
242 }
243 // Add score adjusted for margin of error.
244 score.a.push(aHz);
245 score.b.push(bHz);
246 }
247 // Remove current suite from queue.
248 suites.shift();
249
250 if (suites.length) {
251 // Run next suite.
252 suites[0].run({ 'async': true });
253 }
254 else {
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';
262
263 // Report results.
264 if (aMeanHz >= bMeanHz) {
265 log('\n' + buildName + ' ' + message + ' ' + otherName + '.');
266 } else {
267 log('\n' + otherName + ' ' + message + ' ' + buildName + '.');
268 }
269 }
270 }
271 });
272
273 /*--------------------------------------------------------------------------*/
274
275 lodash.extend(Benchmark.options, {
276 'async': true,
277 'setup': '\
278 var _ = global.underscore,\
279 lodash = global.lodash,\
280 belt = this.name == buildName ? lodash : _;\
281 \
282 var date = new Date,\
283 limit = 50,\
284 regexp = /x/,\
285 object = {},\
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];\
292 \
293 for (var index = 0; index < limit; index++) {\
294 numbers[index] = index;\
295 object["key" + index] = index;\
296 objects[index] = { "num": index };\
297 }\
298 var strNumbers = numbers + "";\
299 \
300 if (typeof assign != "undefined") {\
301 var _assign = _.assign || _.extend,\
302 lodashAssign = lodash.assign;\
303 }\
304 if (typeof bind != "undefined") {\
305 var thisArg = { "name": "fred" };\
306 \
307 var func = function(greeting, punctuation) {\
308 return (greeting || "hi") + " " + this.name + (punctuation || ".");\
309 };\
310 \
311 var _boundNormal = _.bind(func, thisArg),\
312 _boundMultiple = _boundNormal,\
313 _boundPartial = _.bind(func, thisArg, "hi");\
314 \
315 var lodashBoundNormal = lodash.bind(func, thisArg),\
316 lodashBoundMultiple = lodashBoundNormal,\
317 lodashBoundPartial = lodash.bind(func, thisArg, "hi");\
318 \
319 for (index = 0; index < 10; index++) {\
320 _boundMultiple = _.bind(_boundMultiple, { "name": "fred" + index });\
321 lodashBoundMultiple = lodash.bind(lodashBoundMultiple, { "name": "fred" + index });\
322 }\
323 }\
324 if (typeof bindAll != "undefined") {\
325 var bindAllCount = -1,\
326 bindAllObjects = Array(this.count);\
327 \
328 var funcNames = belt.reject(belt.functions(belt).slice(0, 40), function(funcName) {\
329 return /^_/.test(funcName);\
330 });\
331 \
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];\
336 return object;\
337 }, {});\
338 }\
339 }\
340 if (typeof chaining != "undefined") {\
341 var even = function(v) { return v % 2 == 0; },\
342 square = function(v) { return v * v; };\
343 \
344 var largeArray = belt.range(10000),\
345 _chaining = _(largeArray).chain(),\
346 lodashChaining = lodash(largeArray).chain();\
347 }\
348 if (typeof compact != "undefined") {\
349 var uncompacted = numbers.slice();\
350 uncompacted[2] = false;\
351 uncompacted[6] = null;\
352 uncompacted[18] = "";\
353 }\
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; };\
358 \
359 var _composed = _.flowRight && _.flowRight(compAddThree, compAddTwo, compAddOne),\
360 lodashComposed = lodash.flowRight && lodash.flowRight(compAddThree, compAddTwo, compAddOne);\
361 }\
362 if (typeof countBy != "undefined" || typeof omit != "undefined") {\
363 var wordToNumber = {\
364 "one": 1,\
365 "two": 2,\
366 "three": 3,\
367 "four": 4,\
368 "five": 5,\
369 "six": 6,\
370 "seven": 7,\
371 "eight": 8,\
372 "nine": 9,\
373 "ten": 10,\
374 "eleven": 11,\
375 "twelve": 12,\
376 "thirteen": 13,\
377 "fourteen": 14,\
378 "fifteen": 15,\
379 "sixteen": 16,\
380 "seventeen": 17,\
381 "eighteen": 18,\
382 "nineteen": 19,\
383 "twenty": 20,\
384 "twenty-one": 21,\
385 "twenty-two": 22,\
386 "twenty-three": 23,\
387 "twenty-four": 24,\
388 "twenty-five": 25,\
389 "twenty-six": 26,\
390 "twenty-seven": 27,\
391 "twenty-eight": 28,\
392 "twenty-nine": 29,\
393 "thirty": 30,\
394 "thirty-one": 31,\
395 "thirty-two": 32,\
396 "thirty-three": 33,\
397 "thirty-four": 34,\
398 "thirty-five": 35,\
399 "thirty-six": 36,\
400 "thirty-seven": 37,\
401 "thirty-eight": 38,\
402 "thirty-nine": 39,\
403 "forty": 40\
404 };\
405 \
406 var words = belt.keys(wordToNumber).slice(0, limit);\
407 }\
408 if (typeof flatten != "undefined") {\
409 var _flattenDeep = _.flatten([[1]])[0] !== 1,\
410 lodashFlattenDeep = lodash.flatten([[1]])[0] !== 1;\
411 }\
412 if (typeof isEqual != "undefined") {\
413 var objectOfPrimitives = {\
414 "boolean": true,\
415 "number": 1,\
416 "string": "a"\
417 };\
418 \
419 var objectOfObjects = {\
420 "boolean": new Boolean(true),\
421 "number": new Number(1),\
422 "string": new String("a")\
423 };\
424 \
425 var objectOfObjects2 = {\
426 "boolean": new Boolean(true),\
427 "number": new Number(1),\
428 "string": new String("A")\
429 };\
430 \
431 var object2 = {},\
432 object3 = {},\
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]]]];\
439 \
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;\
447 }\
448 object3["key" + (limit - 1)] = -1;\
449 objects3[limit - 1].num = -1;\
450 numbers3[limit - 1] = -1;\
451 }\
452 if (typeof matches != "undefined") {\
453 var source = { "num": 9 };\
454 \
455 var _matcher = (_.matches || _.noop)(source),\
456 lodashMatcher = (lodash.matches || lodash.noop)(source);\
457 }\
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);\
468 }\
469 if (typeof partial != "undefined") {\
470 var func = function(greeting, punctuation) {\
471 return greeting + " fred" + (punctuation || ".");\
472 };\
473 \
474 var _partial = _.partial(func, "hi"),\
475 lodashPartial = lodash.partial(func, "hi");\
476 }\
477 if (typeof template != "undefined") {\
478 var tplData = {\
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"]\
486 };\
487 \
488 var tpl =\
489 "<div>" +\
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>" +\
499 "<% } %>" +\
500 "</ul>" +\
501 "</div>";\
502 \
503 var tplVerbose =\
504 "<div>" +\
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>" +\
514 "<% } %>" +\
515 "</ul>" +\
516 "</div>";\
517 \
518 var settingsObject = { "variable": "data" };\
519 \
520 var _tpl = _.template(tpl),\
521 _tplVerbose = _.template(tplVerbose, null, settingsObject);\
522 \
523 var lodashTpl = lodash.template(tpl),\
524 lodashTplVerbose = lodash.template(tplVerbose, null, settingsObject);\
525 }\
526 if (typeof wrap != "undefined") {\
527 var add = function(a, b) {\
528 return a + b;\
529 };\
530 \
531 var average = function(func, a, b) {\
532 return (func(a, b) / 2).toFixed(2);\
533 };\
534 \
535 var _wrapped = _.wrap(add, average);\
536 lodashWrapped = lodash.wrap(add, average);\
537 }\
538 if (typeof zip != "undefined") {\
539 var unzipped = [["a", "b", "c"], [1, 2, 3], [true, false, true]];\
540 }'
541 });
542
543 /*--------------------------------------------------------------------------*/
544
545 suites.push(
546 Benchmark.Suite('`_(...).map(...).filter(...).take(...).value()`')
547 .add(buildName, {
548 'fn': 'lodashChaining.map(square).filter(even).take(100).value()',
549 'teardown': 'function chaining(){}'
550 })
551 .add(otherName, {
552 'fn': '_chaining.map(square).filter(even).take(100).value()',
553 'teardown': 'function chaining(){}'
554 })
555 );
556
557 /*--------------------------------------------------------------------------*/
558
559 suites.push(
560 Benchmark.Suite('`_.assign`')
561 .add(buildName, {
562 'fn': 'lodashAssign({}, { "a": 1, "b": 2, "c": 3 })',
563 'teardown': 'function assign(){}'
564 })
565 .add(otherName, {
566 'fn': '_assign({}, { "a": 1, "b": 2, "c": 3 })',
567 'teardown': 'function assign(){}'
568 })
569 );
570
571 suites.push(
572 Benchmark.Suite('`_.assign` with multiple sources')
573 .add(buildName, {
574 'fn': 'lodashAssign({}, { "a": 1, "b": 2 }, { "c": 3, "d": 4 })',
575 'teardown': 'function assign(){}'
576 })
577 .add(otherName, {
578 'fn': '_assign({}, { "a": 1, "b": 2 }, { "c": 3, "d": 4 })',
579 'teardown': 'function assign(){}'
580 })
581 );
582
583 /*--------------------------------------------------------------------------*/
584
585 suites.push(
586 Benchmark.Suite('`_.bind` (slow path)')
587 .add(buildName, {
588 'fn': 'lodash.bind(function() { return this.name; }, { "name": "fred" })',
589 'teardown': 'function bind(){}'
590 })
591 .add(otherName, {
592 'fn': '_.bind(function() { return this.name; }, { "name": "fred" })',
593 'teardown': 'function bind(){}'
594 })
595 );
596
597 suites.push(
598 Benchmark.Suite('bound call with arguments')
599 .add(buildName, {
600 'fn': 'lodashBoundNormal("hi", "!")',
601 'teardown': 'function bind(){}'
602 })
603 .add(otherName, {
604 'fn': '_boundNormal("hi", "!")',
605 'teardown': 'function bind(){}'
606 })
607 );
608
609 suites.push(
610 Benchmark.Suite('bound and partially applied call with arguments')
611 .add(buildName, {
612 'fn': 'lodashBoundPartial("!")',
613 'teardown': 'function bind(){}'
614 })
615 .add(otherName, {
616 'fn': '_boundPartial("!")',
617 'teardown': 'function bind(){}'
618 })
619 );
620
621 suites.push(
622 Benchmark.Suite('bound multiple times')
623 .add(buildName, {
624 'fn': 'lodashBoundMultiple()',
625 'teardown': 'function bind(){}'
626 })
627 .add(otherName, {
628 'fn': '_boundMultiple()',
629 'teardown': 'function bind(){}'
630 })
631 );
632
633 /*--------------------------------------------------------------------------*/
634
635 suites.push(
636 Benchmark.Suite('`_.bindAll`')
637 .add(buildName, {
638 'fn': 'lodash.bindAll(bindAllObjects[++bindAllCount], funcNames)',
639 'teardown': 'function bindAll(){}'
640 })
641 .add(otherName, {
642 'fn': '_.bindAll(bindAllObjects[++bindAllCount], funcNames)',
643 'teardown': 'function bindAll(){}'
644 })
645 );
646
647 /*--------------------------------------------------------------------------*/
648
649 suites.push(
650 Benchmark.Suite('`_.clone` with an array')
651 .add(buildName, '\
652 lodash.clone(numbers)'
653 )
654 .add(otherName, '\
655 _.clone(numbers)'
656 )
657 );
658
659 suites.push(
660 Benchmark.Suite('`_.clone` with an object')
661 .add(buildName, '\
662 lodash.clone(object)'
663 )
664 .add(otherName, '\
665 _.clone(object)'
666 )
667 );
668
669 /*--------------------------------------------------------------------------*/
670
671 suites.push(
672 Benchmark.Suite('`_.compact`')
673 .add(buildName, {
674 'fn': 'lodash.compact(uncompacted)',
675 'teardown': 'function compact(){}'
676 })
677 .add(otherName, {
678 'fn': '_.compact(uncompacted)',
679 'teardown': 'function compact(){}'
680 })
681 );
682
683 /*--------------------------------------------------------------------------*/
684
685 suites.push(
686 Benchmark.Suite('`_.countBy` with `callback` iterating an array')
687 .add(buildName, '\
688 lodash.countBy(numbers, function(num) { return num >> 1; })'
689 )
690 .add(otherName, '\
691 _.countBy(numbers, function(num) { return num >> 1; })'
692 )
693 );
694
695 suites.push(
696 Benchmark.Suite('`_.countBy` with `property` name iterating an array')
697 .add(buildName, {
698 'fn': 'lodash.countBy(words, "length")',
699 'teardown': 'function countBy(){}'
700 })
701 .add(otherName, {
702 'fn': '_.countBy(words, "length")',
703 'teardown': 'function countBy(){}'
704 })
705 );
706
707 suites.push(
708 Benchmark.Suite('`_.countBy` with `callback` iterating an object')
709 .add(buildName, {
710 'fn': 'lodash.countBy(wordToNumber, function(num) { return num >> 1; })',
711 'teardown': 'function countBy(){}'
712 })
713 .add(otherName, {
714 'fn': '_.countBy(wordToNumber, function(num) { return num >> 1; })',
715 'teardown': 'function countBy(){}'
716 })
717 );
718
719 /*--------------------------------------------------------------------------*/
720
721 suites.push(
722 Benchmark.Suite('`_.defaults`')
723 .add(buildName, '\
724 lodash.defaults({ "key2": 2, "key6": 6, "key18": 18 }, object)'
725 )
726 .add(otherName, '\
727 _.defaults({ "key2": 2, "key6": 6, "key18": 18 }, object)'
728 )
729 );
730
731 /*--------------------------------------------------------------------------*/
732
733 suites.push(
734 Benchmark.Suite('`_.difference`')
735 .add(buildName, '\
736 lodash.difference(numbers, twoNumbers, fourNumbers)'
737 )
738 .add(otherName, '\
739 _.difference(numbers, twoNumbers, fourNumbers)'
740 )
741 );
742
743 suites.push(
744 Benchmark.Suite('`_.difference` iterating 20 and 40 elements')
745 .add(buildName, {
746 'fn': 'lodash.difference(twentyValues, fortyValues)',
747 'teardown': 'function multiArrays(){}'
748 })
749 .add(otherName, {
750 'fn': '_.difference(twentyValues, fortyValues)',
751 'teardown': 'function multiArrays(){}'
752 })
753 );
754
755 suites.push(
756 Benchmark.Suite('`_.difference` iterating 200 elements')
757 .add(buildName, {
758 'fn': 'lodash.difference(twoHundredValues, twoHundredValues2)',
759 'teardown': 'function multiArrays(){}'
760 })
761 .add(otherName, {
762 'fn': '_.difference(twoHundredValues, twoHundredValues2)',
763 'teardown': 'function multiArrays(){}'
764 })
765 );
766
767 /*--------------------------------------------------------------------------*/
768
769 suites.push(
770 Benchmark.Suite('`_.each` iterating an array')
771 .add(buildName, '\
772 var result = [];\
773 lodash.each(numbers, function(num) {\
774 result.push(num * 2);\
775 })'
776 )
777 .add(otherName, '\
778 var result = [];\
779 _.each(numbers, function(num) {\
780 result.push(num * 2);\
781 })'
782 )
783 );
784
785 suites.push(
786 Benchmark.Suite('`_.each` iterating an object')
787 .add(buildName, '\
788 var result = [];\
789 lodash.each(object, function(num) {\
790 result.push(num * 2);\
791 })'
792 )
793 .add(otherName, '\
794 var result = [];\
795 _.each(object, function(num) {\
796 result.push(num * 2);\
797 })'
798 )
799 );
800
801 /*--------------------------------------------------------------------------*/
802
803 suites.push(
804 Benchmark.Suite('`_.every` iterating an array')
805 .add(buildName, '\
806 lodash.every(numbers, function(num) {\
807 return num < limit;\
808 })'
809 )
810 .add(otherName, '\
811 _.every(numbers, function(num) {\
812 return num < limit;\
813 })'
814 )
815 );
816
817 suites.push(
818 Benchmark.Suite('`_.every` iterating an object')
819 .add(buildName, '\
820 lodash.every(object, function(num) {\
821 return num < limit;\
822 })'
823 )
824 .add(otherName, '\
825 _.every(object, function(num) {\
826 return num < limit;\
827 })'
828 )
829 );
830
831 /*--------------------------------------------------------------------------*/
832
833 suites.push(
834 Benchmark.Suite('`_.filter` iterating an array')
835 .add(buildName, '\
836 lodash.filter(numbers, function(num) {\
837 return num % 2;\
838 })'
839 )
840 .add(otherName, '\
841 _.filter(numbers, function(num) {\
842 return num % 2;\
843 })'
844 )
845 );
846
847 suites.push(
848 Benchmark.Suite('`_.filter` iterating an object')
849 .add(buildName, '\
850 lodash.filter(object, function(num) {\
851 return num % 2\
852 })'
853 )
854 .add(otherName, '\
855 _.filter(object, function(num) {\
856 return num % 2\
857 })'
858 )
859 );
860
861 suites.push(
862 Benchmark.Suite('`_.filter` with `_.matches` shorthand')
863 .add(buildName, {
864 'fn': 'lodash.filter(objects, source)',
865 'teardown': 'function matches(){}'
866 })
867 .add(otherName, {
868 'fn': '_.filter(objects, source)',
869 'teardown': 'function matches(){}'
870 })
871 );
872
873 suites.push(
874 Benchmark.Suite('`_.filter` with `_.matches` predicate')
875 .add(buildName, {
876 'fn': 'lodash.filter(objects, lodashMatcher)',
877 'teardown': 'function matches(){}'
878 })
879 .add(otherName, {
880 'fn': '_.filter(objects, _matcher)',
881 'teardown': 'function matches(){}'
882 })
883 );
884
885 /*--------------------------------------------------------------------------*/
886
887 suites.push(
888 Benchmark.Suite('`_.find` iterating an array')
889 .add(buildName, '\
890 lodash.find(numbers, function(num) {\
891 return num === (limit - 1);\
892 })'
893 )
894 .add(otherName, '\
895 _.find(numbers, function(num) {\
896 return num === (limit - 1);\
897 })'
898 )
899 );
900
901 suites.push(
902 Benchmark.Suite('`_.find` iterating an object')
903 .add(buildName, '\
904 lodash.find(object, function(value, key) {\
905 return /\D9$/.test(key);\
906 })'
907 )
908 .add(otherName, '\
909 _.find(object, function(value, key) {\
910 return /\D9$/.test(key);\
911 })'
912 )
913 );
914
915 // Avoid Underscore induced `OutOfMemoryError` in Rhino and Ringo.
916 suites.push(
917 Benchmark.Suite('`_.find` with `_.matches` shorthand')
918 .add(buildName, {
919 'fn': 'lodash.find(objects, source)',
920 'teardown': 'function matches(){}'
921 })
922 .add(otherName, {
923 'fn': '_.find(objects, source)',
924 'teardown': 'function matches(){}'
925 })
926 );
927
928 /*--------------------------------------------------------------------------*/
929
930 suites.push(
931 Benchmark.Suite('`_.flatten`')
932 .add(buildName, {
933 'fn': 'lodash.flatten(nestedNumbers, !lodashFlattenDeep)',
934 'teardown': 'function flatten(){}'
935 })
936 .add(otherName, {
937 'fn': '_.flatten(nestedNumbers, !_flattenDeep)',
938 'teardown': 'function flatten(){}'
939 })
940 );
941
942 /*--------------------------------------------------------------------------*/
943
944 suites.push(
945 Benchmark.Suite('`_.flattenDeep` nested arrays of numbers')
946 .add(buildName, {
947 'fn': 'lodash.flattenDeep(nestedNumbers)',
948 'teardown': 'function flatten(){}'
949 })
950 .add(otherName, {
951 'fn': '_.flattenDeep(nestedNumbers)',
952 'teardown': 'function flatten(){}'
953 })
954 );
955
956 suites.push(
957 Benchmark.Suite('`_.flattenDeep` nest arrays of objects')
958 .add(buildName, {
959 'fn': 'lodash.flattenDeep(nestedObjects)',
960 'teardown': 'function flatten(){}'
961 })
962 .add(otherName, {
963 'fn': '_.flattenDeep(nestedObjects)',
964 'teardown': 'function flatten(){}'
965 })
966 );
967
968 /*--------------------------------------------------------------------------*/
969
970 suites.push(
971 Benchmark.Suite('`_.flowRight`')
972 .add(buildName, {
973 'fn': 'lodash.flowRight(compAddThree, compAddTwo, compAddOne)',
974 'teardown': 'function flowRight(){}'
975 })
976 .add(otherName, {
977 'fn': '_.flowRight(compAddThree, compAddTwo, compAddOne)',
978 'teardown': 'function flowRight(){}'
979 })
980 );
981
982 suites.push(
983 Benchmark.Suite('composed call')
984 .add(buildName, {
985 'fn': 'lodashComposed(0)',
986 'teardown': 'function flowRight(){}'
987 })
988 .add(otherName, {
989 'fn': '_composed(0)',
990 'teardown': 'function flowRight(){}'
991 })
992 );
993
994 /*--------------------------------------------------------------------------*/
995
996 suites.push(
997 Benchmark.Suite('`_.functions`')
998 .add(buildName, '\
999 lodash.functions(lodash)'
1000 )
1001 .add(otherName, '\
1002 _.functions(lodash)'
1003 )
1004 );
1005
1006 /*--------------------------------------------------------------------------*/
1007
1008 suites.push(
1009 Benchmark.Suite('`_.groupBy` with `callback` iterating an array')
1010 .add(buildName, '\
1011 lodash.groupBy(numbers, function(num) { return num >> 1; })'
1012 )
1013 .add(otherName, '\
1014 _.groupBy(numbers, function(num) { return num >> 1; })'
1015 )
1016 );
1017
1018 suites.push(
1019 Benchmark.Suite('`_.groupBy` with `property` name iterating an array')
1020 .add(buildName, {
1021 'fn': 'lodash.groupBy(words, "length")',
1022 'teardown': 'function countBy(){}'
1023 })
1024 .add(otherName, {
1025 'fn': '_.groupBy(words, "length")',
1026 'teardown': 'function countBy(){}'
1027 })
1028 );
1029
1030 suites.push(
1031 Benchmark.Suite('`_.groupBy` with `callback` iterating an object')
1032 .add(buildName, {
1033 'fn': 'lodash.groupBy(wordToNumber, function(num) { return num >> 1; })',
1034 'teardown': 'function countBy(){}'
1035 })
1036 .add(otherName, {
1037 'fn': '_.groupBy(wordToNumber, function(num) { return num >> 1; })',
1038 'teardown': 'function countBy(){}'
1039 })
1040 );
1041
1042 /*--------------------------------------------------------------------------*/
1043
1044 suites.push(
1045 Benchmark.Suite('`_.includes` searching an array')
1046 .add(buildName, '\
1047 lodash.includes(numbers, limit - 1)'
1048 )
1049 .add(otherName, '\
1050 _.includes(numbers, limit - 1)'
1051 )
1052 );
1053
1054 suites.push(
1055 Benchmark.Suite('`_.includes` searching an object')
1056 .add(buildName, '\
1057 lodash.includes(object, limit - 1)'
1058 )
1059 .add(otherName, '\
1060 _.includes(object, limit - 1)'
1061 )
1062 );
1063
1064 if (lodash.includes('ab', 'ab') && _.includes('ab', 'ab')) {
1065 suites.push(
1066 Benchmark.Suite('`_.includes` searching a string')
1067 .add(buildName, '\
1068 lodash.includes(strNumbers, "," + (limit - 1))'
1069 )
1070 .add(otherName, '\
1071 _.includes(strNumbers, "," + (limit - 1))'
1072 )
1073 );
1074 }
1075
1076 /*--------------------------------------------------------------------------*/
1077
1078 suites.push(
1079 Benchmark.Suite('`_.indexOf`')
1080 .add(buildName, {
1081 'fn': 'lodash.indexOf(hundredSortedValues, 99)',
1082 'teardown': 'function multiArrays(){}'
1083 })
1084 .add(otherName, {
1085 'fn': '_.indexOf(hundredSortedValues, 99)',
1086 'teardown': 'function multiArrays(){}'
1087 })
1088 );
1089
1090 /*--------------------------------------------------------------------------*/
1091
1092 suites.push(
1093 Benchmark.Suite('`_.intersection`')
1094 .add(buildName, '\
1095 lodash.intersection(numbers, twoNumbers, fourNumbers)'
1096 )
1097 .add(otherName, '\
1098 _.intersection(numbers, twoNumbers, fourNumbers)'
1099 )
1100 );
1101
1102 suites.push(
1103 Benchmark.Suite('`_.intersection` iterating 120 elements')
1104 .add(buildName, {
1105 'fn': 'lodash.intersection(hundredTwentyValues, hundredTwentyValues2)',
1106 'teardown': 'function multiArrays(){}'
1107 })
1108 .add(otherName, {
1109 'fn': '_.intersection(hundredTwentyValues, hundredTwentyValues2)',
1110 'teardown': 'function multiArrays(){}'
1111 })
1112 );
1113
1114 /*--------------------------------------------------------------------------*/
1115
1116 suites.push(
1117 Benchmark.Suite('`_.invert`')
1118 .add(buildName, '\
1119 lodash.invert(object)'
1120 )
1121 .add(otherName, '\
1122 _.invert(object)'
1123 )
1124 );
1125
1126 /*--------------------------------------------------------------------------*/
1127
1128 suites.push(
1129 Benchmark.Suite('`_.invokeMap` iterating an array')
1130 .add(buildName, '\
1131 lodash.invokeMap(numbers, "toFixed")'
1132 )
1133 .add(otherName, '\
1134 _.invokeMap(numbers, "toFixed")'
1135 )
1136 );
1137
1138 suites.push(
1139 Benchmark.Suite('`_.invokeMap` with arguments iterating an array')
1140 .add(buildName, '\
1141 lodash.invokeMap(numbers, "toFixed", 1)'
1142 )
1143 .add(otherName, '\
1144 _.invokeMap(numbers, "toFixed", 1)'
1145 )
1146 );
1147
1148 suites.push(
1149 Benchmark.Suite('`_.invokeMap` with a function for `path` iterating an array')
1150 .add(buildName, '\
1151 lodash.invokeMap(numbers, Number.prototype.toFixed, 1)'
1152 )
1153 .add(otherName, '\
1154 _.invokeMap(numbers, Number.prototype.toFixed, 1)'
1155 )
1156 );
1157
1158 suites.push(
1159 Benchmark.Suite('`_.invokeMap` iterating an object')
1160 .add(buildName, '\
1161 lodash.invokeMap(object, "toFixed", 1)'
1162 )
1163 .add(otherName, '\
1164 _.invokeMap(object, "toFixed", 1)'
1165 )
1166 );
1167
1168 /*--------------------------------------------------------------------------*/
1169
1170 suites.push(
1171 Benchmark.Suite('`_.isEqual` comparing primitives')
1172 .add(buildName, {
1173 'fn': '\
1174 lodash.isEqual(1, "1");\
1175 lodash.isEqual(1, 1)',
1176 'teardown': 'function isEqual(){}'
1177 })
1178 .add(otherName, {
1179 'fn': '\
1180 _.isEqual(1, "1");\
1181 _.isEqual(1, 1);',
1182 'teardown': 'function isEqual(){}'
1183 })
1184 );
1185
1186 suites.push(
1187 Benchmark.Suite('`_.isEqual` comparing primitives and their object counterparts (edge case)')
1188 .add(buildName, {
1189 'fn': '\
1190 lodash.isEqual(objectOfPrimitives, objectOfObjects);\
1191 lodash.isEqual(objectOfPrimitives, objectOfObjects2)',
1192 'teardown': 'function isEqual(){}'
1193 })
1194 .add(otherName, {
1195 'fn': '\
1196 _.isEqual(objectOfPrimitives, objectOfObjects);\
1197 _.isEqual(objectOfPrimitives, objectOfObjects2)',
1198 'teardown': 'function isEqual(){}'
1199 })
1200 );
1201
1202 suites.push(
1203 Benchmark.Suite('`_.isEqual` comparing arrays')
1204 .add(buildName, {
1205 'fn': '\
1206 lodash.isEqual(numbers, numbers2);\
1207 lodash.isEqual(numbers2, numbers3)',
1208 'teardown': 'function isEqual(){}'
1209 })
1210 .add(otherName, {
1211 'fn': '\
1212 _.isEqual(numbers, numbers2);\
1213 _.isEqual(numbers2, numbers3)',
1214 'teardown': 'function isEqual(){}'
1215 })
1216 );
1217
1218 suites.push(
1219 Benchmark.Suite('`_.isEqual` comparing nested arrays')
1220 .add(buildName, {
1221 'fn': '\
1222 lodash.isEqual(nestedNumbers, nestedNumbers2);\
1223 lodash.isEqual(nestedNumbers2, nestedNumbers3)',
1224 'teardown': 'function isEqual(){}'
1225 })
1226 .add(otherName, {
1227 'fn': '\
1228 _.isEqual(nestedNumbers, nestedNumbers2);\
1229 _.isEqual(nestedNumbers2, nestedNumbers3)',
1230 'teardown': 'function isEqual(){}'
1231 })
1232 );
1233
1234 suites.push(
1235 Benchmark.Suite('`_.isEqual` comparing arrays of objects')
1236 .add(buildName, {
1237 'fn': '\
1238 lodash.isEqual(objects, objects2);\
1239 lodash.isEqual(objects2, objects3)',
1240 'teardown': 'function isEqual(){}'
1241 })
1242 .add(otherName, {
1243 'fn': '\
1244 _.isEqual(objects, objects2);\
1245 _.isEqual(objects2, objects3)',
1246 'teardown': 'function isEqual(){}'
1247 })
1248 );
1249
1250 suites.push(
1251 Benchmark.Suite('`_.isEqual` comparing objects')
1252 .add(buildName, {
1253 'fn': '\
1254 lodash.isEqual(object, object2);\
1255 lodash.isEqual(object2, object3)',
1256 'teardown': 'function isEqual(){}'
1257 })
1258 .add(otherName, {
1259 'fn': '\
1260 _.isEqual(object, object2);\
1261 _.isEqual(object2, object3)',
1262 'teardown': 'function isEqual(){}'
1263 })
1264 );
1265
1266 /*--------------------------------------------------------------------------*/
1267
1268 suites.push(
1269 Benchmark.Suite('`_.isArguments`, `_.isDate`, `_.isFunction`, `_.isNumber`, `_.isObject`, `_.isRegExp`')
1270 .add(buildName, '\
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)'
1283 )
1284 .add(otherName, '\
1285 _.isArguments(arguments);\
1286 _.isArguments(object);\
1287 _.isDate(date);\
1288 _.isDate(object);\
1289 _.isFunction(_);\
1290 _.isFunction(object);\
1291 _.isNumber(1);\
1292 _.isNumber(object);\
1293 _.isObject(object);\
1294 _.isObject(1);\
1295 _.isRegExp(regexp);\
1296 _.isRegExp(object)'
1297 )
1298 );
1299
1300 /*--------------------------------------------------------------------------*/
1301
1302 suites.push(
1303 Benchmark.Suite('`_.keys` (uses native `Object.keys` if available)')
1304 .add(buildName, '\
1305 lodash.keys(object)'
1306 )
1307 .add(otherName, '\
1308 _.keys(object)'
1309 )
1310 );
1311
1312 /*--------------------------------------------------------------------------*/
1313
1314 suites.push(
1315 Benchmark.Suite('`_.lastIndexOf`')
1316 .add(buildName, {
1317 'fn': 'lodash.lastIndexOf(hundredSortedValues, 0)',
1318 'teardown': 'function multiArrays(){}'
1319 })
1320 .add(otherName, {
1321 'fn': '_.lastIndexOf(hundredSortedValues, 0)',
1322 'teardown': 'function multiArrays(){}'
1323 })
1324 );
1325
1326 /*--------------------------------------------------------------------------*/
1327
1328 suites.push(
1329 Benchmark.Suite('`_.map` iterating an array')
1330 .add(buildName, '\
1331 lodash.map(objects, function(value) {\
1332 return value.num;\
1333 })'
1334 )
1335 .add(otherName, '\
1336 _.map(objects, function(value) {\
1337 return value.num;\
1338 })'
1339 )
1340 );
1341
1342 suites.push(
1343 Benchmark.Suite('`_.map` iterating an object')
1344 .add(buildName, '\
1345 lodash.map(object, function(value) {\
1346 return value;\
1347 })'
1348 )
1349 .add(otherName, '\
1350 _.map(object, function(value) {\
1351 return value;\
1352 })'
1353 )
1354 );
1355
1356 suites.push(
1357 Benchmark.Suite('`_.map` with `_.property` shorthand')
1358 .add(buildName, '\
1359 lodash.map(objects, "num")'
1360 )
1361 .add(otherName, '\
1362 _.map(objects, "num")'
1363 )
1364 );
1365
1366 /*--------------------------------------------------------------------------*/
1367
1368 suites.push(
1369 Benchmark.Suite('`_.max`')
1370 .add(buildName, '\
1371 lodash.max(numbers)'
1372 )
1373 .add(otherName, '\
1374 _.max(numbers)'
1375 )
1376 );
1377
1378 /*--------------------------------------------------------------------------*/
1379
1380 suites.push(
1381 Benchmark.Suite('`_.min`')
1382 .add(buildName, '\
1383 lodash.min(numbers)'
1384 )
1385 .add(otherName, '\
1386 _.min(numbers)'
1387 )
1388 );
1389
1390 /*--------------------------------------------------------------------------*/
1391
1392 suites.push(
1393 Benchmark.Suite('`_.omit` iterating 20 properties, omitting 2 keys')
1394 .add(buildName, '\
1395 lodash.omit(object, "key6", "key13")'
1396 )
1397 .add(otherName, '\
1398 _.omit(object, "key6", "key13")'
1399 )
1400 );
1401
1402 suites.push(
1403 Benchmark.Suite('`_.omit` iterating 40 properties, omitting 20 keys')
1404 .add(buildName, {
1405 'fn': 'lodash.omit(wordToNumber, words)',
1406 'teardown': 'function omit(){}'
1407 })
1408 .add(otherName, {
1409 'fn': '_.omit(wordToNumber, words)',
1410 'teardown': 'function omit(){}'
1411 })
1412 );
1413
1414 /*--------------------------------------------------------------------------*/
1415
1416 suites.push(
1417 Benchmark.Suite('`_.partial` (slow path)')
1418 .add(buildName, {
1419 'fn': 'lodash.partial(function(greeting) { return greeting + " " + this.name; }, "hi")',
1420 'teardown': 'function partial(){}'
1421 })
1422 .add(otherName, {
1423 'fn': '_.partial(function(greeting) { return greeting + " " + this.name; }, "hi")',
1424 'teardown': 'function partial(){}'
1425 })
1426 );
1427
1428 suites.push(
1429 Benchmark.Suite('partially applied call with arguments')
1430 .add(buildName, {
1431 'fn': 'lodashPartial("!")',
1432 'teardown': 'function partial(){}'
1433 })
1434 .add(otherName, {
1435 'fn': '_partial("!")',
1436 'teardown': 'function partial(){}'
1437 })
1438 );
1439
1440 /*--------------------------------------------------------------------------*/
1441
1442 suites.push(
1443 Benchmark.Suite('`_.partition` iterating an array')
1444 .add(buildName, '\
1445 lodash.partition(numbers, function(num) {\
1446 return num % 2;\
1447 })'
1448 )
1449 .add(otherName, '\
1450 _.partition(numbers, function(num) {\
1451 return num % 2;\
1452 })'
1453 )
1454 );
1455
1456 suites.push(
1457 Benchmark.Suite('`_.partition` iterating an object')
1458 .add(buildName, '\
1459 lodash.partition(object, function(num) {\
1460 return num % 2;\
1461 })'
1462 )
1463 .add(otherName, '\
1464 _.partition(object, function(num) {\
1465 return num % 2;\
1466 })'
1467 )
1468 );
1469
1470 /*--------------------------------------------------------------------------*/
1471
1472 suites.push(
1473 Benchmark.Suite('`_.pick`')
1474 .add(buildName, '\
1475 lodash.pick(object, "key6", "key13")'
1476 )
1477 .add(otherName, '\
1478 _.pick(object, "key6", "key13")'
1479 )
1480 );
1481
1482 /*--------------------------------------------------------------------------*/
1483
1484 suites.push(
1485 Benchmark.Suite('`_.reduce` iterating an array')
1486 .add(buildName, '\
1487 lodash.reduce(numbers, function(result, value, index) {\
1488 result[index] = value;\
1489 return result;\
1490 }, {})'
1491 )
1492 .add(otherName, '\
1493 _.reduce(numbers, function(result, value, index) {\
1494 result[index] = value;\
1495 return result;\
1496 }, {})'
1497 )
1498 );
1499
1500 suites.push(
1501 Benchmark.Suite('`_.reduce` iterating an object')
1502 .add(buildName, '\
1503 lodash.reduce(object, function(result, value, key) {\
1504 result.push(key, value);\
1505 return result;\
1506 }, [])'
1507 )
1508 .add(otherName, '\
1509 _.reduce(object, function(result, value, key) {\
1510 result.push(key, value);\
1511 return result;\
1512 }, [])'
1513 )
1514 );
1515
1516 /*--------------------------------------------------------------------------*/
1517
1518 suites.push(
1519 Benchmark.Suite('`_.reduceRight` iterating an array')
1520 .add(buildName, '\
1521 lodash.reduceRight(numbers, function(result, value, index) {\
1522 result[index] = value;\
1523 return result;\
1524 }, {})'
1525 )
1526 .add(otherName, '\
1527 _.reduceRight(numbers, function(result, value, index) {\
1528 result[index] = value;\
1529 return result;\
1530 }, {})'
1531 )
1532 );
1533
1534 suites.push(
1535 Benchmark.Suite('`_.reduceRight` iterating an object')
1536 .add(buildName, '\
1537 lodash.reduceRight(object, function(result, value, key) {\
1538 result.push(key, value);\
1539 return result;\
1540 }, [])'
1541 )
1542 .add(otherName, '\
1543 _.reduceRight(object, function(result, value, key) {\
1544 result.push(key, value);\
1545 return result;\
1546 }, [])'
1547 )
1548 );
1549
1550 /*--------------------------------------------------------------------------*/
1551
1552 suites.push(
1553 Benchmark.Suite('`_.reject` iterating an array')
1554 .add(buildName, '\
1555 lodash.reject(numbers, function(num) {\
1556 return num % 2;\
1557 })'
1558 )
1559 .add(otherName, '\
1560 _.reject(numbers, function(num) {\
1561 return num % 2;\
1562 })'
1563 )
1564 );
1565
1566 suites.push(
1567 Benchmark.Suite('`_.reject` iterating an object')
1568 .add(buildName, '\
1569 lodash.reject(object, function(num) {\
1570 return num % 2;\
1571 })'
1572 )
1573 .add(otherName, '\
1574 _.reject(object, function(num) {\
1575 return num % 2;\
1576 })'
1577 )
1578 );
1579
1580 /*--------------------------------------------------------------------------*/
1581
1582 suites.push(
1583 Benchmark.Suite('`_.sampleSize`')
1584 .add(buildName, '\
1585 lodash.sampleSize(numbers, limit / 2)'
1586 )
1587 .add(otherName, '\
1588 _.sampleSize(numbers, limit / 2)'
1589 )
1590 );
1591
1592 /*--------------------------------------------------------------------------*/
1593
1594 suites.push(
1595 Benchmark.Suite('`_.shuffle`')
1596 .add(buildName, '\
1597 lodash.shuffle(numbers)'
1598 )
1599 .add(otherName, '\
1600 _.shuffle(numbers)'
1601 )
1602 );
1603
1604 /*--------------------------------------------------------------------------*/
1605
1606 suites.push(
1607 Benchmark.Suite('`_.size` with an object')
1608 .add(buildName, '\
1609 lodash.size(object)'
1610 )
1611 .add(otherName, '\
1612 _.size(object)'
1613 )
1614 );
1615
1616 /*--------------------------------------------------------------------------*/
1617
1618 suites.push(
1619 Benchmark.Suite('`_.some` iterating an array')
1620 .add(buildName, '\
1621 lodash.some(numbers, function(num) {\
1622 return num == (limit - 1);\
1623 })'
1624 )
1625 .add(otherName, '\
1626 _.some(numbers, function(num) {\
1627 return num == (limit - 1);\
1628 })'
1629 )
1630 );
1631
1632 suites.push(
1633 Benchmark.Suite('`_.some` iterating an object')
1634 .add(buildName, '\
1635 lodash.some(object, function(num) {\
1636 return num == (limit - 1);\
1637 })'
1638 )
1639 .add(otherName, '\
1640 _.some(object, function(num) {\
1641 return num == (limit - 1);\
1642 })'
1643 )
1644 );
1645
1646 /*--------------------------------------------------------------------------*/
1647
1648 suites.push(
1649 Benchmark.Suite('`_.sortBy` with `callback`')
1650 .add(buildName, '\
1651 lodash.sortBy(numbers, function(num) { return Math.sin(num); })'
1652 )
1653 .add(otherName, '\
1654 _.sortBy(numbers, function(num) { return Math.sin(num); })'
1655 )
1656 );
1657
1658 suites.push(
1659 Benchmark.Suite('`_.sortBy` with `property` name')
1660 .add(buildName, {
1661 'fn': 'lodash.sortBy(words, "length")',
1662 'teardown': 'function countBy(){}'
1663 })
1664 .add(otherName, {
1665 'fn': '_.sortBy(words, "length")',
1666 'teardown': 'function countBy(){}'
1667 })
1668 );
1669
1670 /*--------------------------------------------------------------------------*/
1671
1672 suites.push(
1673 Benchmark.Suite('`_.sortedIndex`')
1674 .add(buildName, '\
1675 lodash.sortedIndex(numbers, limit)'
1676 )
1677 .add(otherName, '\
1678 _.sortedIndex(numbers, limit)'
1679 )
1680 );
1681
1682 /*--------------------------------------------------------------------------*/
1683
1684 suites.push(
1685 Benchmark.Suite('`_.sortedIndexBy`')
1686 .add(buildName, {
1687 'fn': '\
1688 lodash.sortedIndexBy(words, "twenty-five", function(value) {\
1689 return wordToNumber[value];\
1690 })',
1691 'teardown': 'function countBy(){}'
1692 })
1693 .add(otherName, {
1694 'fn': '\
1695 _.sortedIndexBy(words, "twenty-five", function(value) {\
1696 return wordToNumber[value];\
1697 })',
1698 'teardown': 'function countBy(){}'
1699 })
1700 );
1701
1702 /*--------------------------------------------------------------------------*/
1703
1704 suites.push(
1705 Benchmark.Suite('`_.sortedIndexOf`')
1706 .add(buildName, {
1707 'fn': 'lodash.sortedIndexOf(hundredSortedValues, 99)',
1708 'teardown': 'function multiArrays(){}'
1709 })
1710 .add(otherName, {
1711 'fn': '_.sortedIndexOf(hundredSortedValues, 99)',
1712 'teardown': 'function multiArrays(){}'
1713 })
1714 );
1715
1716 /*--------------------------------------------------------------------------*/
1717
1718 suites.push(
1719 Benchmark.Suite('`_.sortedLastIndexOf`')
1720 .add(buildName, {
1721 'fn': 'lodash.sortedLastIndexOf(hundredSortedValues, 0)',
1722 'teardown': 'function multiArrays(){}'
1723 })
1724 .add(otherName, {
1725 'fn': '_.sortedLastIndexOf(hundredSortedValues, 0)',
1726 'teardown': 'function multiArrays(){}'
1727 })
1728 );
1729
1730 /*--------------------------------------------------------------------------*/
1731
1732 suites.push(
1733 Benchmark.Suite('`_.sum`')
1734 .add(buildName, '\
1735 lodash.sum(numbers)'
1736 )
1737 .add(otherName, '\
1738 _.sum(numbers)'
1739 )
1740 );
1741
1742 /*--------------------------------------------------------------------------*/
1743
1744 suites.push(
1745 Benchmark.Suite('`_.template` (slow path)')
1746 .add(buildName, {
1747 'fn': 'lodash.template(tpl)(tplData)',
1748 'teardown': 'function template(){}'
1749 })
1750 .add(otherName, {
1751 'fn': '_.template(tpl)(tplData)',
1752 'teardown': 'function template(){}'
1753 })
1754 );
1755
1756 suites.push(
1757 Benchmark.Suite('compiled template')
1758 .add(buildName, {
1759 'fn': 'lodashTpl(tplData)',
1760 'teardown': 'function template(){}'
1761 })
1762 .add(otherName, {
1763 'fn': '_tpl(tplData)',
1764 'teardown': 'function template(){}'
1765 })
1766 );
1767
1768 suites.push(
1769 Benchmark.Suite('compiled template without a with-statement')
1770 .add(buildName, {
1771 'fn': 'lodashTplVerbose(tplData)',
1772 'teardown': 'function template(){}'
1773 })
1774 .add(otherName, {
1775 'fn': '_tplVerbose(tplData)',
1776 'teardown': 'function template(){}'
1777 })
1778 );
1779
1780 /*--------------------------------------------------------------------------*/
1781
1782 suites.push(
1783 Benchmark.Suite('`_.times`')
1784 .add(buildName, '\
1785 var result = [];\
1786 lodash.times(limit, function(n) { result.push(n); })'
1787 )
1788 .add(otherName, '\
1789 var result = [];\
1790 _.times(limit, function(n) { result.push(n); })'
1791 )
1792 );
1793
1794 /*--------------------------------------------------------------------------*/
1795
1796 suites.push(
1797 Benchmark.Suite('`_.toArray` with an array (edge case)')
1798 .add(buildName, '\
1799 lodash.toArray(numbers)'
1800 )
1801 .add(otherName, '\
1802 _.toArray(numbers)'
1803 )
1804 );
1805
1806 suites.push(
1807 Benchmark.Suite('`_.toArray` with an object')
1808 .add(buildName, '\
1809 lodash.toArray(object)'
1810 )
1811 .add(otherName, '\
1812 _.toArray(object)'
1813 )
1814 );
1815
1816 /*--------------------------------------------------------------------------*/
1817
1818 suites.push(
1819 Benchmark.Suite('`_.toPairs`')
1820 .add(buildName, '\
1821 lodash.toPairs(object)'
1822 )
1823 .add(otherName, '\
1824 _.toPairs(object)'
1825 )
1826 );
1827
1828 /*--------------------------------------------------------------------------*/
1829
1830 suites.push(
1831 Benchmark.Suite('`_.unescape` string without html entities')
1832 .add(buildName, '\
1833 lodash.unescape("`&`, `<`, `>`, `\\"`, and `\'`")'
1834 )
1835 .add(otherName, '\
1836 _.unescape("`&`, `<`, `>`, `\\"`, and `\'`")'
1837 )
1838 );
1839
1840 suites.push(
1841 Benchmark.Suite('`_.unescape` string with html entities')
1842 .add(buildName, '\
1843 lodash.unescape("`&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;`")'
1844 )
1845 .add(otherName, '\
1846 _.unescape("`&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;`")'
1847 )
1848 );
1849
1850 /*--------------------------------------------------------------------------*/
1851
1852 suites.push(
1853 Benchmark.Suite('`_.union`')
1854 .add(buildName, '\
1855 lodash.union(numbers, twoNumbers, fourNumbers)'
1856 )
1857 .add(otherName, '\
1858 _.union(numbers, twoNumbers, fourNumbers)'
1859 )
1860 );
1861
1862 suites.push(
1863 Benchmark.Suite('`_.union` iterating an array of 200 elements')
1864 .add(buildName, {
1865 'fn': 'lodash.union(hundredValues, hundredValues2)',
1866 'teardown': 'function multiArrays(){}'
1867 })
1868 .add(otherName, {
1869 'fn': '_.union(hundredValues, hundredValues2)',
1870 'teardown': 'function multiArrays(){}'
1871 })
1872 );
1873
1874 /*--------------------------------------------------------------------------*/
1875
1876 suites.push(
1877 Benchmark.Suite('`_.uniq`')
1878 .add(buildName, '\
1879 lodash.uniq(numbers.concat(twoNumbers, fourNumbers))'
1880 )
1881 .add(otherName, '\
1882 _.uniq(numbers.concat(twoNumbers, fourNumbers))'
1883 )
1884 );
1885
1886 suites.push(
1887 Benchmark.Suite('`_.uniq` iterating an array of 200 elements')
1888 .add(buildName, {
1889 'fn': 'lodash.uniq(twoHundredValues)',
1890 'teardown': 'function multiArrays(){}'
1891 })
1892 .add(otherName, {
1893 'fn': '_.uniq(twoHundredValues)',
1894 'teardown': 'function multiArrays(){}'
1895 })
1896 );
1897
1898 /*--------------------------------------------------------------------------*/
1899
1900 suites.push(
1901 Benchmark.Suite('`_.uniqBy`')
1902 .add(buildName, '\
1903 lodash.uniqBy(numbers.concat(twoNumbers, fourNumbers), function(num) {\
1904 return num % 2;\
1905 })'
1906 )
1907 .add(otherName, '\
1908 _.uniqBy(numbers.concat(twoNumbers, fourNumbers), function(num) {\
1909 return num % 2;\
1910 })'
1911 )
1912 );
1913
1914 /*--------------------------------------------------------------------------*/
1915
1916 suites.push(
1917 Benchmark.Suite('`_.values`')
1918 .add(buildName, '\
1919 lodash.values(object)'
1920 )
1921 .add(otherName, '\
1922 _.values(object)'
1923 )
1924 );
1925
1926 /*--------------------------------------------------------------------------*/
1927
1928 suites.push(
1929 Benchmark.Suite('`_.without`')
1930 .add(buildName, '\
1931 lodash.without(numbers, 9, 12, 14, 15)'
1932 )
1933 .add(otherName, '\
1934 _.without(numbers, 9, 12, 14, 15)'
1935 )
1936 );
1937
1938 /*--------------------------------------------------------------------------*/
1939
1940 suites.push(
1941 Benchmark.Suite('`_.wrap` result called')
1942 .add(buildName, {
1943 'fn': 'lodashWrapped(2, 5)',
1944 'teardown': 'function wrap(){}'
1945 })
1946 .add(otherName, {
1947 'fn': '_wrapped(2, 5)',
1948 'teardown': 'function wrap(){}'
1949 })
1950 );
1951
1952 /*--------------------------------------------------------------------------*/
1953
1954 suites.push(
1955 Benchmark.Suite('`_.zip`')
1956 .add(buildName, {
1957 'fn': 'lodash.zip.apply(lodash, unzipped)',
1958 'teardown': 'function zip(){}'
1959 })
1960 .add(otherName, {
1961 'fn': '_.zip.apply(_, unzipped)',
1962 'teardown': 'function zip(){}'
1963 })
1964 );
1965
1966 /*--------------------------------------------------------------------------*/
1967
1968 if (Benchmark.platform + '') {
1969 log(Benchmark.platform);
1970 }
1971 // Expose `run` to be called later when executing in a browser.
1972 if (document) {
1973 root.run = run;
1974 } else {
1975 run();
1976 }
1977}.call(this));