Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash fp v4 flow vs Native
(version: 3)
Comparing performance of:
lodash fp vs native vs native with lodash vs native with named funcs
Created:
5 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdn.jsdelivr.net/g/lodash@4(lodash.min.js+lodash.fp.min.js)'></script>
Script Preparation code:
var fp = _.noConflict(); var context = { eventline: { hello: 'you' }, config: 'sadas', }; var isString = fp.isString; var isArray = fp.isArray; var getDefaultProps = fp.flow( fp.filter( _.overEvery([ isString, function (prop) { return _.hasIn(context, prop); }, ]), ), fp.reduce(function (acc, i) { acc[i] = context[i]; return acc; }, {}), ); var testNative = function(param) { param.filter(myVar => (typeof myVar === 'string' || myVar instanceof String) && context[myVar]).reduce(function (acc, i) { acc[i] = context[i]; return acc; }, {}) } var testNativeDash = function(param) { param.filter(myVar => _.isString(myVar) && _.hasIn(context, myVar)).reduce(function (acc, i) { acc[i] = context[i]; return acc; }, {}) } var isStr = myVar => typeof myVar === 'string' || myVar instanceof String; var isWithinObj = myVar => !!context[myVar]; var reducer = function (acc, i) { acc[i] = context[i]; return acc; } var testNativeWithFunc = function(param) { param.filter(myVar => isStr(myVar) && isWithinObj(myVar)).reduce(reducer, {}) } var test1 = ['eventline']
Tests:
lodash fp
getDefaultProps(test1);
native
testNative(test1)
native with lodash
testNativeDash(test1)
native with named funcs
testNativeWithFunc(test1)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
lodash fp
native
native with lodash
native with named funcs
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Definition JSON** The benchmark definition defines four test cases, each testing a different approach to filter and transform an object. The main differences between these approaches lie in how they handle string properties and how they define functions for filtering and transforming. 1. **Native**: This implementation uses JavaScript's built-in `filter()` and `reduce()` methods, along with the `typeof` operator to check if a value is a string. It defines two helper functions, `isStr` and `reducer`, which are used inside the `filter()` callback. 2. **Native with named funcs**: Similar to the native implementation, but instead of using inline anonymous functions, it uses separate named functions for filtering (`isStr`) and transforming (`reducer`). 3. **Native with lodash**: This implementation uses the Lodash library's `isString` and `hasIn` functions to filter and transform the object. It defines two helper functions, `isStr` and `reducer`, which are used inside the `filter()` callback. 4. **Lodash fp**: This implementation uses Lodash's functional programming (fp) utilities, such as `flow` and `reduceBy`, to filter and transform the object. **Pros and Cons of each approach** * **Native**: + Pros: Fast, lightweight, and easy to understand for JavaScript native developers. + Cons: May be less concise and more verbose compared to other approaches. * **Native with named funcs**: + Pros: Easier to read and maintain than inline anonymous functions. + Cons: May be slightly slower due to the overhead of function calls. * **Native with lodash**: + Pros: Uses optimized Lodash functions, which can lead to better performance. + Cons: Requires an additional dependency (Lodash library). * **Lodash fp**: + Pros: Provides a concise and expressive way of writing functional code. + Cons: May be less familiar to developers without prior experience with fp. **Library usage** The Lodash library is used in two test cases: 1. **Native with lodash**: Uses `isString` and `hasIn` functions from the Lodash library. 2. **Lodash fp**: Uses `flow` and `reduceBy` utilities from the Lodash fp library. **Special JS features or syntax** The benchmark uses the following special JavaScript features or syntax: * Arrow functions (e.g., `myVar => typeof myVar === 'string'`) * Rest parameter (not used in this example) * Spread operator (not used in this example) Other alternatives For those interested in alternative approaches, here are a few options: 1. **ES6+ features**: Using modern JavaScript features like `Object.entries()` and `Array.prototype.filter()` could provide similar performance to the native approach. 2. **React or DOM manipulation libraries**: Implementing the benchmark using React or a DOM manipulation library (e.g., jQuery) could provide an interesting comparison, especially for filtering and transforming data in a more complex context. 3. **Other functional programming libraries**: Depending on personal preference, other functional programming libraries like Ramda or fp.js could be used to implement the benchmark. These alternatives are not directly related to the specific question of how different approaches handle string properties and function definitions, but they provide additional perspectives for developers interested in exploring various JavaScript implementation options.
Related benchmarks:
Lodash Chain vs Native (with &&) vs Native (without &&) vs Flow
Lodash Chain (with &&) vs Native (with &&) vs Native (without &&) vs Flow
Lodash Chain vs Native vs Flow
Lodash Chain vs Native (with &&) vs Native (without &&) vs Flow, with actual filtering
Comments
Confirm delete:
Do you really want to delete benchmark?