From 6c3a17de718eba0f2dadc298f6c93816c466a470 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 4 Oct 2014 11:13:28 -0700 Subject: [PATCH] Add lazy chaining benchmark. --- perf/perf.js | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/perf/perf.js b/perf/perf.js index f00aad74b..3f78960d9 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -343,8 +343,12 @@ }\ }\ if (typeof chaining != "undefined") {\ - var _chaining = _.chain ? _(numbers).chain() : _(numbers),\ - lodashChaining = lodash(numbers);\ + var odd = function(v) { return !!(v % 2); },\ + square = function(v) { return v * v; };\ + \ + var largeArray = belt.range(10000),\ + _chaining = _.chain ? _(largeArray).chain() : _(largeArray),\ + lodashChaining = lodash(largeArray);\ }\ if (typeof compact != "undefined") {\ var uncompacted = numbers.slice();\ @@ -537,7 +541,7 @@ /*--------------------------------------------------------------------------*/ suites.push( - Benchmark.Suite('`_(...)` with a number') + Benchmark.Suite('`_(...)` with a number (edge case)') .add(buildName, '\ lodash(2)' ) @@ -566,20 +570,17 @@ ) ); - // avoid Underscore induced `OutOfMemoryError` in Rhino, Narwhal, and Ringo - if (!isJava) { - suites.push( - Benchmark.Suite('`_(...).tap(...)`') - .add(buildName, { - 'fn': 'lodashChaining.tap(lodash.identity)', - 'teardown': 'function chaining(){}' - }) - .add(otherName, { - 'fn': '_chaining.tap(_.identity)', - 'teardown': 'function chaining(){}' - }) - ); - } + suites.push( + Benchmark.Suite('`_(...).map(...).filter(...).take(...).value()`') + .add(buildName, { + 'fn': 'lodashChaining.map(square).filter(odd).take(100).value()', + 'teardown': 'function chaining(){}' + }) + .add(otherName, { + 'fn': '_chaining.map(square).filter(odd).take(100).value()', + 'teardown': 'function chaining(){}' + }) + ); /*--------------------------------------------------------------------------*/