<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>
let obj = Immutable.Map();
for(i=0;i<10000;i++){
const key = 'key'+i;
const value = 'value'+i;
obj.set(key, {key, value});
}
let obj = new Map();
for(i=0;i<10000;i++){
const key = 'key'+i;
const value = 'value'+i;
obj.set(key, {key, value});
}
let obj = Immutable.Map();
for(i=0;i<10000;i++){
const key = 'key'+i;
const value = 'value'+i;
obj.set(key, {key, value});
}
for(i=0;i<10000;i++){
const key = 'key'+i;
if (obj.has(key)) {
const temp = obj.get(key);
}
}
let obj = new Map();
for(i=0;i<10000;i++){
const key = 'key'+i;
const value = 'value'+i;
obj.set(key, {key, value})
}
for(i=0;i<10000;i++){
const key = 'key'+i;
if (obj.has(key)) {
const temp = obj.get(key);
}
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
immutable Map | |
Native Javascript Map | |
Read immutable Map | |
Read Native Javascript Map |
Test name | Executions per second |
---|---|
immutable Map | 1750.8 Ops/sec |
Native Javascript Map | 819.5 Ops/sec |
Read immutable Map | 1058.9 Ops/sec |
Read Native Javascript Map | 624.4 Ops/sec |
Let's dive into the explanation.
Benchmark Definition
The benchmark measures the performance of two approaches: using Immutable.js and native JavaScript Maps for storing and retrieving data.
Options Compared
There are four test cases:
get
method.get
method.Pros and Cons
Library Used
Special JS Feature/Syntax
None mentioned in the provided benchmark definition.
Other Considerations
Alternatives
Keep in mind that these considerations are specific to this particular benchmark, and the choice of approach ultimately depends on the use case and requirements.