From 9f19c302d8a0afcd0788942cb3ae8447e5004c7b Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 3 Mar 2013 23:58:07 -0800 Subject: [PATCH] Cleanup `_.bind` benchmarks and add chaining benchmarks. [ci skip] Former-commit-id: 9198c34679709610a440f71856a3869eaa83090e --- perf/perf.js | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/perf/perf.js b/perf/perf.js index ece6f3e4d..8f179ccfb 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -224,18 +224,18 @@ }\ \ if (typeof bind != "undefined") {\ - var contextObject = { "name": "moe" },\ + var thisArg = { "name": "moe" },\ ctor = function() {};\ \ var func = function(greeting, punctuation) {\ return greeting + ", " + this.name + (punctuation || ".");\ };\ \ - var lodashBoundNormal = lodash.bind(func, contextObject),\ - lodashBoundPartial = lodash.bind(func, contextObject, "hi");\ + var _boundNormal = _.bind(func, thisArg),\ + _boundPartial = _.bind(func, thisArg, "hi");\ \ - var _boundNormal = _.bind(func, contextObject),\ - _boundPartial = _.bind(func, contextObject, "hi");\ + var lodashBoundNormal = lodash.bind(func, thisArg),\ + lodashBoundPartial = lodash.bind(func, thisArg, "hi");\ }\ \ if (typeof bindAll != "undefined") {\ @@ -250,6 +250,10 @@ }, {});\ }\ }\ + if (typeof chaining != "undefined") {\ + var _chaining = _(numbers).chain(),\ + lodashChaining = lodash(numbers);\ + }\ if (typeof compact != "undefined") {\ var uncompacted = numbers.slice();\ uncompacted[2] = false;\ @@ -457,6 +461,40 @@ /*--------------------------------------------------------------------------*/ + suites.push( + Benchmark.Suite('`_(...)` with a number') + .add(buildName, '\ + lodash(2)' + ) + .add(otherName, '\ + _(2)' + ) + ); + + suites.push( + Benchmark.Suite('`_(...)` with an object') + .add(buildName, '\ + lodash(object)' + ) + .add(otherName, '\ + _(object)' + ) + ); + + suites.push( + Benchmark.Suite('`_(...).map(...)`') + .add(buildName, { + 'fn': 'lodashChaining.map(lodash.identity)', + 'teardown': 'function chaining(){}' + }) + .add(otherName, { + 'fn': '_chaining.map(_.identity)', + 'teardown': 'function chaining(){}' + }) + ); + + /*--------------------------------------------------------------------------*/ + suites.push( Benchmark.Suite('`_.bind` (uses native `Function#bind` if available and inferred fast)') .add(buildName, { @@ -1716,7 +1754,6 @@ if (Benchmark.platform + '') { log(Benchmark.platform); } - // in the browser, expose `run` to be called later if (window.document && !window.phantom) { window.run = run;