Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Vanilla (+ Chained) vs Lodash FP vs Native
(version: 0)
Comparing performance of:
Lodash Vanilla vs Lodash Vanilla (Chained) vs Lodash FP vs Native
Created:
6 years ago
by:
Guest
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 arr = [ { type: 'foo', name: 'foo' }, { type: 'bar', name: 'bar' }, { type: 'foo', name: 'a' }, { type: 'bar', name: 'b' }, { type: 'foo', name: 'c' }, { type: 'cat', name: 'cat' }, { type: 'foo', name: 'foo' }, { type: 'bar', name: 'uuu' }, { type: 'bar', name: 'tttt' }, { type: 'nothing', name: 'foo' }, { type: 'foo', name: 'x' } ]; var _mapFn = (item) => Object.assign({}, {name: item.name.toUpperCase()}); var _filterFn = (item) => item.type === 'foo';
Tests:
Lodash Vanilla
const result = _.filter(_.map(arr, _mapFn), _filterFn);
Lodash Vanilla (Chained)
const result = _(arr).map(_mapFn).filter(_filterFn).value();
Lodash FP
const result = fp.flow(fp.map(_mapFn), fp.filter(_filterFn))(arr);
Native
const result = arr.map(_mapFn).filter(_filterFn);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Lodash Vanilla
Lodash Vanilla (Chained)
Lodash FP
Native
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 benchmark and explain what is being tested, the options compared, their pros and cons, and other considerations. **Benchmark Overview** The benchmark compares the performance of three approaches to filter an array: Lodash Vanilla, Lodash FP (Functional Programming), and Native (using native JavaScript). The test case uses a sample array `arr` with different types of objects. **Options Compared** 1. **Lodash Vanilla**: This approach uses the traditional, non-functional programming style, where the `_filterFn` function is called directly on the `map()` result. 2. **Lodash FP (Functional Programming)**: This approach uses a functional programming style, where the `_filterFn` function is passed as an argument to the `map()` and `filter()` methods. 3. **Native**: This approach uses native JavaScript syntax, without relying on Lodash. **Pros and Cons** 1. **Lodash Vanilla**: * Pros: Easy to read and understand for developers familiar with traditional programming style. * Cons: May not be as efficient due to the direct function call. 2. **Lodash FP (Functional Programming)**: * Pros: Can lead to more concise and elegant code, making it easier to reason about and test. * Cons: May require a steeper learning curve for developers unfamiliar with functional programming concepts. 3. **Native**: * Pros: Native performance and no dependencies on external libraries. * Cons: Requires manual handling of the iteration process, which can be error-prone. **Library and Syntax** The benchmark uses Lodash as a library. Lodash is a popular JavaScript utility library that provides functional programming-style functions for tasks like array manipulation, object manipulation, and more. In the `Script Preparation Code`, we see the `_.noConflict()` method being used to create a separate scope for the Lodash functions. This is necessary because Lodash's functions can sometimes interfere with each other if called from the global scope. The benchmark also defines two custom function literals `_mapFn` and `_filterFn`, which are passed as arguments to the `map()` and `filter()` methods, respectively. **Special JS Features** There is no special JavaScript feature or syntax being tested in this benchmark. The focus is on comparing different approaches to array filtering using Lodash and native JavaScript. **Alternatives** If you're interested in exploring alternative libraries for functional programming-style array manipulation, some popular options include: 1. **Underscore.js**: Another popular utility library that provides similar functionality to Lodash. 2. **Ramda**: A functional programming library specifically designed for JavaScript that offers a more comprehensive set of functions. 3. **Immer**: A state management library that also provides functional programming-style array manipulation functions. If you prefer not to use external libraries, you can implement your own functional programming-style array filtering functions using native JavaScript syntax. This approach requires manual handling of the iteration process and may require more code, but can be a good learning experience for developers familiar with functional programming concepts.
Related benchmarks:
_.get Benchmark Test
ES6 Optional Chaining vs. ES6 Optional Chaining vs. Lodash _.get
ES6 Optional Chaining vs TS Optional Chaining result in javascript vs vs. Lodash _.get
optional chaining chrome vs lodash get
Lodash _.has vs Optional Chaining
Comments
Confirm delete:
Do you really want to delete benchmark?