Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
object spread vs immutable-js set vs Map 3
(version: 3)
Comparing performance of:
Spread vs ImmutableJS vs Map vs Map with converting to Object after the operations
Created:
3 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.2/immutable.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/immutability-helper@2.7.0/index.min.js"></script>
Tests:
Spread
let obj = {}; for(i=0;i<1000;i++){ const key = 'key'+i const value = 'value'+i obj = {...obj, [key]: {key, value}} }
ImmutableJS
let obj = Immutable.Map(); for(i=0;i<1000;i++){ const key = 'key'+i const value = 'value'+i obj = obj.set(key, {key, value}) }
Map
const obj = new Map(); for(i=0;i<1000;i++){ const key = 'key'+i const value = 'value'+i obj.set(key, {key, value}) }
Map with converting to Object after the operations
const obj = new Map(); for(i=0;i<1000;i++){ const key = 'key'+i const value = 'value'+i obj.set(key, {key, value}) } Object.fromEntries(obj)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Spread
ImmutableJS
Map
Map with converting to Object after the operations
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 on MeasureThat.net. The provided JSON represents a benchmark with four test cases: 1. **Object Spread**: This test case creates an empty object and then iterates 1000 times, assigning new key-value pairs to it using the spread operator (`{...obj, [key]: {key, value}}`). 2. **ImmutableJS Set**: This test case uses the Immutable.js library to create a map and then iterates 1000 times, setting new key-value pairs on it using the `set()` method. 3. **Map**: This test case creates an empty Map object and then iterates 1000 times, setting new key-value pairs on it using the `set()` method. Finally, it converts the Map to an Object using the `Object.fromEntries()` method. 4. **Map with converting to Object after operations**: This test case is similar to the previous one but includes an additional step where it converts the Map to an Object immediately after all operations. Now, let's discuss the options being compared: * **ImmutableJS Set vs Map**: The main difference between these two approaches is that ImmutableJS Set creates a new data structure every time you set a value, whereas the native JavaScript Map and the spread operator create a new object reference each time. This means that ImmutableJS Set might have higher overhead due to frequent garbage collection. * **Map with converting to Object after operations vs without**: Converting the Map to an Object can reduce memory usage by eliminating the need for a separate Map data structure. However, this approach also requires extra work, as it inlines the conversion step into the benchmarking loop. **Pros and Cons:** * **ImmutableJS Set**: + Pros: Immutable.js provides a predictable and thread-safe way to work with immutable data structures. + Cons: As mentioned earlier, frequent garbage collection can lead to higher overhead. * **Map**: + Pros: Native JavaScript Maps are efficient and lightweight compared to Immutable.js Sets. + Cons: The spread operator creates a new object reference each time, which might lead to slower performance compared to ImmutableJS Set. * **Spread Operator**: + Pros: Creates a new object reference with minimal overhead. + Cons: As mentioned earlier, it can lead to higher garbage collection frequencies. Other considerations: * **Library usage**: The benchmark uses the Immutable.js library for its Set implementation. This is not specific to JavaScript but rather a third-party dependency. * **Special JS feature or syntax**: There's no mention of special features like async/await, Promises, or web workers in this benchmark. However, it's essential to note that many modern benchmarks often include these aspects to simulate real-world scenarios. **Alternatives:** For comparison purposes, other alternatives could be: * Using native JavaScript objects instead of Immutable.js Sets. * Implementing a custom immutable data structure using techniques like memoization or function caching. * Comparing the performance of different programming languages or frameworks that support concurrent execution (e.g., Node.js vs. .NET Core). Keep in mind that benchmarking is an iterative process, and results may vary depending on specific use cases, hardware configurations, and software versions. I hope this explanation helps you understand the benchmark's context and the underlying choices made by the developer!
Related benchmarks:
object spread vs immutable-js set vs native Map
Spread operator vs Immutable.js performance for common use cases
object spread vs immutable-js set vs native Map copy
object spread vs immutable-js set vs native Map vs object
Comments
Confirm delete:
Do you really want to delete benchmark?