Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set (Lodash vs Lodash/fp vs Immutable) comp. test
(version: 1)
Comparing performance of:
native (mutations) vs lodash (mutations) vs lodash/fp vs immutable
Created:
2 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 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(); var im = Immutable; var original = { x: { y: { z: 123 }}}; function pureJs(obj, path, value) { const keys = Object.keys(path); let current = obj; for (let i = 0; i < keys.length - 1; i++) { const key = keys[i]; if (!current[key]) { current[key] = {}; } current = current[key]; } current[keys[keys.length - 1]] = value; }
Tests:
native (mutations)
pureJs(original, ['x', 'y', 'z'], 456)
lodash (mutations)
_.set(original, ['x', 'y', 'z'], 456)
lodash/fp
fp.set(original, ['x', 'y', 'z'], 456)
immutable
im.setIn(original, ['x', 'y', 'z'], 456)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
native (mutations)
lodash (mutations)
lodash/fp
immutable
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0
Browser/OS:
Chrome 134 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
native (mutations)
6620969.0 Ops/sec
lodash (mutations)
2246520.8 Ops/sec
lodash/fp
294842.4 Ops/sec
immutable
550770.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks, comparing different approaches and libraries to achieve similar results. The provided benchmark measures the performance of three sets of functions: 1. Lodash (mutations): `_set` function from the Lodash library. 2. Lodash/fp (mutations): `fp.set` function from the Lodash/fp library. 3. Immutable: `setIn` function from the Immutable library. The benchmark tests how quickly each set of functions can update a nested object by setting a new value at a specific path. **Options Compared** The three options compared are: 1. **Lodash (mutations)**: The `_set` function in Lodash updates the value at a specified path without creating intermediate objects, which reduces memory usage and makes it faster for large arrays and objects. 2. **Lodash/fp (mutations)**: The `fp.set` function in Lodash/fp is similar to `_set`, but with additional features like memoization and currying. 3. **Immutable**: The `setIn` function in Immutable creates a new object every time, which can lead to slower performance due to the creation of intermediate objects. **Pros and Cons** 1. **Lodash (mutations)**: * Pros: Fast and memory-efficient, especially for large arrays and objects. * Cons: May not work well with complex data structures or multiple updates at different paths. 2. **Lodash/fp (mutations)**: * Pros: Offers additional features like memoization and currying, which can improve performance in some cases. * Cons: May introduce overhead due to the added complexity. 3. **Immutable**: * Pros: Encourages a functional programming style, making it easier to reason about code. * Cons: Can lead to slower performance due to the creation of intermediate objects. **Library and Syntax** The Lodash library provides a set of utility functions for functional programming in JavaScript. The `set` function updates the value at a specified path without creating intermediate objects, which makes it efficient for large arrays and objects. Lodash/fp is a variant of Lodash that adds additional features like memoization and currying to improve performance. The `fp.set` function is similar to `_set`, but with these added features. The Immutable library provides an immutable data structure system, where all data is immutable by default. This approach encourages a functional programming style and makes it easier to reason about code. **Special JS Feature or Syntax** There are no special JavaScript features or syntax mentioned in the benchmark definition. The tests use standard JavaScript functions like `Object.keys()` and array indexing. **Other Alternatives** If you're looking for alternative approaches, consider: 1. **Native JavaScript**: You can implement a custom solution using only native JavaScript functions. 2. **Fp.js**: Fp.js is another functional programming library that provides similar functionality to Lodash/fp. 3. **Reactive Extensions (RxJS)**: RxJS is a library for reactive programming, which can be used to create observable sequences and handle asynchronous updates. Keep in mind that the choice of approach depends on your specific use case and performance requirements.
Related benchmarks:
object spread vs immutable-js set vs object mutate
object spread vs immutable-js set vs native Map
object spread vs immutable-js set vs Map
object spread vs immutable-js set vs Map 3
Comments
Confirm delete:
Do you really want to delete benchmark?