From c9c83ee7e6ef9a11cdd85e05050ee579aa18a0ae Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 14 Jul 2012 06:21:59 -0400 Subject: [PATCH] Add `_.invoke` benchmark to perf.js and a link to the compatibility changes wiki entry in README.md. Former-commit-id: 51296709ea8d9dd6e951530b9874b90af3c764a2 --- README.md | 2 +- perf/perf.js | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 66e7deb11..afa72ca32 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Lo-Dash v0.4.1 -A drop-in replacement for Underscore.js, from the devs behind [jsPerf.com](http://jsperf.com), that delivers [performance improvements](http://lodash.com/benchmarks), [bug fixes](https://github.com/bestiejs/lodash#closed-underscorejs-issues), and [additional features](https://github.com/bestiejs/lodash#features). +A drop-in replacement[*](https://github.com/bestiejs/lodash/wiki/Drop-in-Disclaimer) for Underscore.js, from the devs behind [jsPerf.com](http://jsperf.com), that delivers [performance improvements](http://lodash.com/benchmarks), [bug fixes](https://github.com/bestiejs/lodash#closed-underscorejs-issues), and [additional features](https://github.com/bestiejs/lodash#features). Lo-Dash’s performance is gained by avoiding slower native methods, instead opting for simplified non-ES5 compliant methods optimized for common usage, and by leveraging function compilation to reduce the number of overall function calls. diff --git a/perf/perf.js b/perf/perf.js index 5a696456b..3b7c18bec 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -602,12 +602,12 @@ suites.push( Benchmark.Suite('`_.find` iterating an object') .add('Lo-Dash', function() { - lodash.find(numbers, function(value, key) { + lodash.find(object, function(value, key) { return /\D9$/.test(key); }); }) .add('Underscore', function() { - _.find(numbers, function(value, key) { + _.find(object, function(value, key) { return /\D9$/.test(key); }); }) @@ -727,6 +727,39 @@ /*--------------------------------------------------------------------------*/ + suites.push( + Benchmark.Suite('`_.invoke` iterating an array') + .add('Lo-Dash', function() { + lodash.invoke(numbers, 'toFixed', '2'); + }) + .add('Underscore', function() { + _.invoke(numbers, 'toFixed', '2'); + }) + ); + + suites.push( + Benchmark.Suite('`_.invoke` with a function for `methodName` iterating an array') + .add('Lo-Dash', function() { + lodash.invoke(numbers, String.prototype.split, ''); + }) + .add('Underscore', function() { + _.invoke(numbers, String.prototype.split, ''); + }) + ); + + suites.push( + Benchmark.Suite('`_.invoke` iterating an object') + .add('Lo-Dash', function() { + lodash.invoke(object, 'toFixed', '2'); + }) + .add('Underscore', function() { + _.invoke(object, 'toFixed', '2'); + }) + ); + + /*--------------------------------------------------------------------------*/ + + suites.push( Benchmark.Suite('`_.isEqual` comparing primitives and objects (edge case)') .add('Lo-Dash', {