From 268ce91c65caed431fde71e2c8540d23381d68ab Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 2 Jul 2012 00:07:55 -0400 Subject: [PATCH] Add `_.bind` and `_.size` benchmarks. Former-commit-id: bb3517e9517db81de56e3794abc256cd2dac59b5 --- perf/perf.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/perf/perf.js b/perf/perf.js index dcc90223c..9e80361e9 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -76,8 +76,11 @@ nestedNumbers = [1, [2], [3, [[4]]]], twoNumbers = [12, 21]; - var ctor = function() { }, - func = function(greeting) { return greeting + ': ' + this.name; }; + var ctor = function() { }; + + var func = function(greeting, punctuation) { + return greeting + ', ' + this.name + (punctuation || '.'); + }; var lodashBoundNormal = lodash.bind(func, { 'name': 'moe' }), lodashBoundCtor = lodash.bind(ctor, { 'name': 'moe' }), @@ -184,7 +187,7 @@ /*--------------------------------------------------------------------------*/ suites.push( - Benchmark.Suite('`_.bind` (will use native if available and inferred fast)') + Benchmark.Suite('`_.bind` (uses native `Function#bind` if available and inferred fast)') .add('Lo-Dash', function() { lodash.bind(func, { 'name': 'moe' }, 'hi'); }) @@ -204,7 +207,17 @@ ); suites.push( - Benchmark.Suite('bound and partially applied call') + Benchmark.Suite('bound call with arguments') + .add('Lo-Dash', function() { + lodashBoundNormal('hi', '!'); + }) + .add('Underscore', function() { + _boundNormal('hi', '!'); + }) + ); + + suites.push( + Benchmark.Suite('bound and partially applied call (uses native `Function#bind` if available)') .add('Lo-Dash', function() { lodashBoundPartial(); }) @@ -213,6 +226,16 @@ }) ); + suites.push( + Benchmark.Suite('bound and partially applied call with arguments (uses native `Function#bind` if available)') + .add('Lo-Dash', function() { + lodashBoundPartial('!'); + }) + .add('Underscore', function() { + _boundPartial('!'); + }) + ); + suites.push( Benchmark.Suite('bound and called in a `new` expression, i.e. `new bound` (edge case)') .add('Lo-Dash', function() { @@ -491,6 +514,28 @@ /*--------------------------------------------------------------------------*/ + suites.push( + Benchmark.Suite('`_.size` with an array') + .add('Lo-Dash', function() { + lodash.size(numbers); + }) + .add('Underscore', function() { + _.size(numbers); + }) + ); + + suites.push( + Benchmark.Suite('`_.size` with an object') + .add('Lo-Dash', function() { + lodash.size(object); + }) + .add('Underscore', function() { + _.size(object); + }) + ); + + /*--------------------------------------------------------------------------*/ + suites.push( Benchmark.Suite('`_.sortBy` with `callback`') .add('Lo-Dash', function() {