Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Immer (setAutoFreeze(false), setUseProxies(true)) vs shallow vs ramda evolve
(version: 1)
Comparing performance of:
immer vs shallow copy vs ramda evolve
Created:
6 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://unpkg.com/immer/dist/immer.umd.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
Script Preparation code:
var { evolve, assoc, append } = R var INITIAL_DATA = { items: {}, count: 0, keys: [] } for (var index = 0; index < 100; index++) { INITIAL_DATA.items[index] = { id: index, name: `ITEM-${index}`, value: Math.random() } INITIAL_DATA.count++ INITIAL_DATA.keys.push(index) } var NEW_ITEM_ID = INITIAL_DATA.count; var produce = immer.default immer.setAutoFreeze(false) immer.setUseProxies(true)
Tests:
immer
data = produce(INITIAL_DATA, draft => { draft.items[NEW_ITEM_ID] = { id: NEW_ITEM_ID, name: 'ITEM-NEW', value: 0 } draft.count++ draft.keys.push(NEW_ITEM_ID) })
shallow copy
data = { ...INITIAL_DATA, items: { ...INITIAL_DATA.items, [NEW_ITEM_ID]: { id: NEW_ITEM_ID, name: 'ITEM-NEW', value: 0 } }, count: INITIAL_DATA.count +1, keys: [ ...INITIAL_DATA.keys, NEW_ITEM_ID] }
ramda evolve
data = evolve({ items: assoc(NEW_ITEM_ID, {id: NEW_ITEM_ID, name: "ITEM-NEW", value: 0}), count: x => x + 1, keys: append(NEW_ITEM_ID) }, INITIAL_DATA);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
immer
shallow copy
ramda evolve
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 dive into the world of JavaScript microbenchmarks. **Benchmark Overview** The benchmark compares three approaches to update a dataset: 1. **Immer**: uses its `produce` function to create a new draft copy of the data, which is then used as the new state. 2. **Shallow Copy**: creates a shallow copy of the original data using the spread operator (`...`) and then updates it manually. 3. **Ramda Evolve**: uses Ramda's `evolve` function to update the data in a functional programming style. **Immer (setAutoFreeze(false), setUseProxies(true))** * Immer is a library that provides a simple and efficient way to work with immutable data structures. * In this benchmark, Immer's `produce` function is used to create a new draft copy of the data. The `setAutoFreeze(false)` option tells Immer not to automatically freeze the object, allowing us to update it manually. The `setUseProxies(true)` option enables proxy-based updates, which can improve performance. * Pros: + Efficient and easy to use + Reduces memory allocation and garbage collection overhead * Cons: + Can be slower than shallow copy due to the additional overhead of creating a new draft copy **Shallow Copy** * A shallow copy creates a new object that references the original object's properties. * In this benchmark, we create a shallow copy using the spread operator (`...`) and then update it manually. * Pros: + Fast and lightweight + Easy to implement and understand * Cons: + Can lead to memory leaks if not implemented carefully (e.g., when updating nested objects) **Ramda Evolve** * Ramda is a functional programming library that provides a powerful way to work with data structures. * In this benchmark, the `evolve` function is used to update the data. The `assoc` function is used to add a new property to an object, while the `append` function is used to append a value to an array. * Pros: + Can be faster and more efficient than shallow copy due to the immutability guarantees + Provides a higher-level abstraction for working with data structures * Cons: + Can be slower than Immer's `produce` function due to the additional overhead of functional programming operations **Library Analysis** * **Immer**: a popular library for working with immutable data structures. Its `produce` function is efficient and easy to use. * **Ramda**: a powerful functional programming library that provides a high-level abstraction for working with data structures. **Special JS Features/Syntax** None mentioned in this benchmark. **Other Alternatives** If you're looking for alternative approaches, consider the following: * **Lodash**: a popular utility library that provides a comprehensive set of functions for working with data structures. * **Functional programming libraries like LoomJS or js-iterable**: can provide an alternative to Ramda's `evolve` function. Keep in mind that the choice of approach depends on your specific use case, performance requirements, and personal preferences.
Related benchmarks:
Immer (setAutoFreeze(false)) vs shallow vs ramda lens vs samless immutable111
Immer vs shallow vs ramda lens (2)
Immer (setAutoFreeze(false)) vs shallow vs ramda lens vs samless immutable111 2
Immer (setAutoFreeze(true)) vs shallow vs ramda lens vs samless immutable111 2
Comments
Confirm delete:
Do you really want to delete benchmark?