Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Immer (setAutoFreeze(false)) vs shallow vs ramda lens V2
(version: 0)
Comparing performance of:
immer vs shallow copy vs ramda lens
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://unpkg.com/immer/dist/immer.umd.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
Script Preparation code:
var { compose, over, set, lensPath, append } = R var INITIAL_DATA = { items: {}, count: 0, keys: [] } for (var index = 0; index < 100; index++) { INITIAL_DATA[index] = { id: index, name: `ITEM-${index}`, value: Math.random() } INITIAL_DATA.count++ INITIAL_DATA.keys.push(index) } var NEW_ITEM_ID = INITIAL_DATA.count +1 var produce = immer.default immer.setAutoFreeze(false)
Tests:
immer
data = produce(INITIAL_DATA, draft => { draft.items[NEW_ITEM_ID] = { id: NEW_ITEM_ID, name: 'ITEM-NEW', value: 0 } draft.counter++ 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 lens
data = compose( over(lensPath(["keys"]), append(NEW_ITEM_ID)), over(lensPath(["count"]), x => x + 1), set(lensPath(["items", NEW_ITEM_ID]), { id: NEW_ITEM_ID, name: "ITEM-NEW", value: 0 }) )(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 lens
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):
Measuring JavaScript performance is a complex task, and I'll break it down for you. **Overview** The provided benchmark compares three approaches to manipulate a large data object: 1. `Immer` (setAutoFreeze(false)): A library that provides a safe and efficient way to mutate objects. 2. Shallow copy: A simple approach to create a new object by copying an existing one. 3. Ramda Lens V2: A functional programming library that allows you to update nested data structures using lens functions. **Options Compared** The benchmark tests the performance of each approach: * `Immer`: Creates a draft object and mutates it in-place, without creating a new copy. * Shallow copy: Creates a new object by copying an existing one using the spread operator (`{ ...INITIAL_DATA }`). * Ramda Lens V2: Uses lens functions to update nested data structures. **Pros and Cons** 1. **Immer**: * Pros: Efficient, safe, and convenient. * Cons: May have higher memory overhead due to the draft object, and can be slower for very large datasets. 2. Shallow copy: * Pros: Simple, easy to understand, and fast. * Cons: May not be suitable for large datasets or complex data structures. 3. Ramda Lens V2: * Pros: Provides a functional programming approach, allowing for composable and reusable code. * Cons: May have higher learning curve due to the use of lens functions, and can be slower than Imperative approaches. **Library: Ramda Lens** Ramda Lens is a library that provides a way to update nested data structures using lens functions. A lens function takes a value as input and returns another value by applying a transformation. In this benchmark, the lens function `lensPath([\"keys\"], append(NEW_ITEM_ID))` updates the `keys` array at a specific path. **Special JS Feature/Syntax** None mentioned in this benchmark. However, it's worth noting that some JavaScript features like async/await, ES6 classes, and modern syntax might impact performance. **Other Alternatives** If you're interested in exploring other approaches, consider: * Immutable.js: A library that provides a similar API to Ramda Lens but with an emphasis on immutable data structures. * Lodash: Another utility library that includes functions for working with objects and arrays. * Lo-Dash: A functional programming library that provides a different set of lens-like functions. Keep in mind that each approach has its strengths and weaknesses, and the choice ultimately depends on your specific use case and performance requirements.
Related benchmarks:
Immer (setAutoFreeze(false)) vs shallow vs ramda lens vs samless immutable111
Immer (setAutoFreeze(false)) vs shallow vs ramda lens vs immutabe js vs immutable js (toJS) vs mutating 2.0
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?