Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
immutable vs Native Javascript Map With Read Complex With Count New
(version: 0)
immutable vs Native Javascript Map With Read
Comparing performance of:
immutable Map vs Native Javascript Map vs Read immutable Map vs Read Native Javascript Map
Created:
3 years ago
by:
Guest
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:
immutable Map
let obj = Immutable.Map(); for(i=0;i<10000;i++){ const key = ['key'+i, i]; const value = 'value'+i; obj.set(key, {key, value}); }
Native Javascript Map
let obj = new Map(); for(i=0;i<10000;i++){ const key = ['key'+i, i]; const value = 'value'+i; obj.set(key, {key, value}); }
Read immutable Map
let obj = Immutable.Map(); for(i=0;i<10000;i++){ const key = ['key'+i, i]; const value = 'value'+i; obj.set(key, {key, value}); } let count = 0; for(i=0;i<10000;i++){ const key = ['key'+i, i]; if (obj.has(key)) { count++; const temp = obj.get(key); } } console.log('Immutable Map:: ', count);
Read Native Javascript Map
let obj = new Map(); for(i=0;i<10000;i++){ const key = ['key'+i, i]; const value = 'value'+i; obj.set(key, {key, value}) } let count = 0; for(i=0;i<10000;i++){ const key = ['key'+i, i]; if (obj.has(key)) { count++; const temp = obj.get(key); } } console.log('Map:: ', count);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
immutable Map
Native Javascript Map
Read immutable Map
Read Native Javascript Map
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. **What is being tested?** The provided benchmark compares the performance of two data structures: Immutable Maps and Native JavaScript Maps, both used for storing key-value pairs. The focus is on three scenarios: 1. **Insertion**: Creating a new Map (Immutable or Native) and inserting 10,000 key-value pairs. 2. **Read with Count**: Inserting 10,000 key-value pairs into a Map (Immutable or Native), then reading the value associated with each key and counting the number of occurrences. **Options compared** The two main options being tested are: 1. **Immutable Maps**: Using the Immutable.js library to create a read-only Map. 2. **Native JavaScript Maps**: Using the built-in `Map` data structure in JavaScript. **Pros and Cons of each approach:** * **Immutable Maps (Immutable.js)**: + Pros: - Ensures data integrity and thread-safety - Can be more convenient for certain use cases, such as logging or analytics + Cons: - Slower performance compared to Native JavaScript Maps due to the overhead of the Immutable library - May not be suitable for applications requiring frequent modifications to the Map's contents * **Native JavaScript Maps**: + Pros: - Faster performance compared to Immutable Maps - Suitable for most use cases, including those requiring frequent modifications to the Map's contents + Cons: - May introduce concurrency issues or data inconsistencies if not used carefully **Library and its purpose** The `Immutable` library is a popular JavaScript library that provides immutable data structures, such as Maps, Sets, Lists, and more. Its primary goal is to ensure data integrity and thread-safety by using immutable data structures. In the context of this benchmark, Immutable Maps are used to create a read-only Map, which helps prevent unintended modifications during the execution of the test case. **Special JS feature or syntax** This benchmark does not specifically utilize any special JavaScript features or syntax, such as async/await, Promises, or WebAssembly. The focus is on comparing the performance of Immutable Maps and Native JavaScript Maps. **Other alternatives** If you're interested in exploring alternative data structures for your applications, here are a few options: 1. **WeakMaps**: A type of Map that allows for garbage collection to occur when keys are deleted. 2. **Set**: An unordered collection of unique values, often used for fast lookups and insertions. 3. **Map (using WeakKeyMap)**: A variant of the `Map` data structure that uses weak references for its keys. Keep in mind that each alternative has its own trade-offs and use cases.
Related benchmarks:
Immutable.Set Union vs Constructing a new plain JS Set
immutable vs Native Javascript Map With Read
immutable vs Native Javascript Map With Read Complex
immutable vs Native Javascript Map With Read Complex With Count
Comments
Confirm delete:
Do you really want to delete benchmark?