Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Immer (setAutoFreeze(false)) vs shallow vs ramda lens vs immutable js
(version: 0)
Comparing performance of:
immer vs shallow copy vs ramda lens vs Immutable js test
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/immer/8.0.1/immer.umd.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.2/immutable.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) var immutable = Immutable.fromJS(INITIAL_DATA)
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);
Immutable js test
data = immutable.withMutations((state) => { state.update('items', items => items.set(NEW_ITEM_ID, { id: NEW_ITEM_ID, name: "ITEM-NEW", value: 0 })); state.set('count', INITIAL_DATA + 1); state.update('keys', keys => keys.push(NEW_ITEM_ID)); })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
immer
shallow copy
ramda lens
Immutable js test
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 the performance of JavaScript data structures and libraries is an essential task for any developer. Let's break down what each test case is testing: 1. **Immer**: Immer is a library that provides a simple way to manage immutable data structures in JavaScript. In this benchmark, it tests the performance of creating a new object with a shallow copy of the initial data and then appending a new item to it. 2. **Shallow Copy**: This test case simply creates a shallow copy of the initial data using the spread operator (`{ ...INITIAL_DATA }`). 3. **Ramda Lens**: Ramda Lens is a library that provides a way to update nested objects in a functional programming style. In this benchmark, it tests the performance of using Ramda Lens to update a specific property of an object. 4. **Immutable Js**: Immutable Js is a library that enforces immutable data structures and provides a way to create new objects by cloning existing ones. In this benchmark, it tests the performance of creating a new object with Immutable Js. Now, let's discuss the options being compared: * **Immer** vs **Shallow Copy**: Both approaches are similar in that they aim to create a new object from the initial data. However, Immer provides more features, such as handling nested objects and arrays, whereas Shallow Copy is limited to simple copying of objects. + Pros of Immer: More features, better support for nested objects and arrays. + Cons of Immer: Overhead due to its immutable nature, which can lead to performance issues in certain cases. * **Ramda Lens** vs **Immutable Js**: Both libraries provide a way to update nested objects in a functional programming style. However, Ramda Lens is more focused on data manipulation, whereas Immutable Js provides a broader range of features for building immutable applications. + Pros of Ramda Lens: Better suited for data manipulation tasks, more concise syntax. + Cons of Ramda Lens: Limited support for certain data structures, such as arrays. * **Immer** vs **Ramda Lens**: Both libraries provide similar functionality for creating and updating objects. However, Immer is more geared towards simple data management, whereas Ramda Lens provides a more comprehensive set of tools for data manipulation. + Pros of Immer: Simpler syntax, better support for basic data structures. + Cons of Immer: Less feature-rich compared to Ramda Lens. Other considerations: * **Immutable data structures**: All four libraries aim to provide immutable data structures, which can lead to performance benefits in certain cases. However, this comes at the cost of additional overhead and complexity. * **Concurrency**: If multiple threads or processes are accessing shared data, using an immutable library like Immer or Immutable Js can help prevent concurrency issues. Alternatives: * **Lodash**: Lodash is a utility library that provides various functions for working with arrays and objects. While not specifically designed for immutable data structures, it can be used to achieve similar results. * **Plain JavaScript**: In some cases, using plain JavaScript without any libraries can lead to performance benefits due to the lack of overhead. In summary, each test case is evaluating the performance of a specific library or approach in creating and updating objects. By comparing different options, developers can choose the best tool for their needs based on factors like complexity, features, 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 (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?