Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map (Lodash vs Lodash/fp vs Immutable) new versions
(version: 0)
Comparing performance of:
Array.prototype.map vs lodash.map vs Immutable.map vs lodash/fp.map
Created:
2 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 type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/immutable/5.0.0-beta.4/immutable.min.js'></script>
Script Preparation code:
var fp = _.noConflict(); function double(n) { return n*2; } var data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30];
Tests:
Array.prototype.map
data.map(double);
lodash.map
_.map(data, double);
Immutable.map
Immutable.fromJS(data).map(double)
lodash/fp.map
fp.map(double)(data)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Array.prototype.map
lodash.map
Immutable.map
lodash/fp.map
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array.prototype.map
3738006.2 Ops/sec
lodash.map
5867343.5 Ops/sec
Immutable.map
726491.0 Ops/sec
lodash/fp.map
876869.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the benchmarking setup. **What is being tested?** MeasureThat.net is testing the performance of different JavaScript libraries for mapping (applying a function to each element) over an array: Lodash, Lodash/FP (Functional Programming), and Immutable.js. The test cases specifically focus on the `map` function in each library. **Options compared** The benchmark compares the following options: 1. **Lodash**: `_map(data, double)` - using Lodash's `map` function with its default behavior. 2. **Lodash/FP**: `fp.map(double)(data)` - using Lodash/FP's `map` function, which is designed for functional programming and uses a different implementation than the standard Lodash `map`. 3. **Immutable.js**: `Immutable.fromJS(data).map(double)` - using Immutable.js's `map` function to transform an immutable data structure. **Pros and cons of each approach** 1. **Lodash**: * Pros: Familiar API, widely used, and well-maintained. * Cons: May not be optimized for performance, as it's designed for a more general-purpose utility library. 2. **Lodash/FP**: * Pros: Optimized for functional programming, which can lead to better performance in certain scenarios. * Cons: Steeper learning curve due to its functional programming focus and different API than standard Lodash. 3. **Immutable.js**: * Pros: Designed specifically for immutable data structures, which can lead to more predictable and efficient code. * Cons: May require additional setup and understanding of Immutable.js's design principles. **Library-specific considerations** 1. **Lodash**: The `map` function in Lodash uses a V8 engine-optimized implementation under the hood, which is why it's so fast. However, this also means that the benchmark may not accurately represent the overhead introduced by the library's utility functions. 2. **Immutable.js**: Immutable.js's `map` function transforms an immutable data structure, which can lead to more predictable and efficient code. However, this transformation comes at a cost in terms of execution speed, as it involves creating new objects. **Other considerations** 1. **JavaScript engine optimizations**: The benchmark results may vary depending on the JavaScript engine used (e.g., V8, SpiderMonkey) and its optimizations. 2. **Browser-specific quirks**: Different browsers may implement or optimize certain features differently, which can affect benchmark results. 3. **Data size and complexity**: The performance of mapping functions can be influenced by the size and structure of the input data. **Alternatives** 1. **Other mapping libraries**: Other JavaScript libraries like Ramda, Jest, or BaconJS offer similar functionality to Lodash, but with different design principles and optimization strategies. 2. **Native JavaScript implementation**: Some developers may choose to implement a custom mapping function using native JavaScript, which can provide optimal performance but requires more expertise. In summary, the benchmark compares three popular JavaScript libraries for mapping over arrays: Lodash, Lodash/FP, and Immutable.js. The results highlight the trade-offs between different optimization strategies, library design principles, and execution speed.
Related benchmarks:
immutable vs lodash vs ...
immutable vs lodash vs ... 4
immutable vs lodash vs ... 5
Map (Lodash vs Lodash/fp vs Immutable)
Comments
Confirm delete:
Do you really want to delete benchmark?