<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, i];
const value = 'value'+i;
obj.set(key, {key, value});
}
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 obj = Immutable.Map();
for(i=0;i<10000;i++){
const key = ['key'+i, i];
const value = 'value'+i;
obj.set(key, {key, value});
}
for(i=0;i<10000;i++){
const key = ['key'+i, i];
if (obj.has(key)) {
const temp = obj.get(key);
}
}
let obj = new Map();
for(i=0;i<10000;i++){
const key = ['key'+i, i];
const value = 'value'+i;
obj.set(key, {key, value})
}
for(i=0;i<10000;i++){
const key = ['key'+i, 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 | 1424.0 Ops/sec |
Native Javascript Map | 717.8 Ops/sec |
Read immutable Map | 1073.0 Ops/sec |
Read Native Javascript Map | 445.0 Ops/sec |
Let's dive into the world of JavaScript microbenchmarks.
Benchmark Overview
The provided benchmark measures the performance of two data structures: Immutable Maps and native JavaScript Maps, with additional scenarios for reading values from these maps. The goal is to compare the execution speed of these two approaches in different scenarios.
Immutable Maps vs Native JavaScript Maps
Both Immutable Maps and native JavaScript Maps are used as key-value stores in JavaScript. However, they have some differences:
Options Compared
The benchmark compares two options:
Pros and Cons of Each Approach
Additional Scenarios
The benchmark also includes additional scenarios:
These additional scenarios help to further evaluate the performance characteristics of each approach, especially when it comes to accessing values in a map.
Library: Immutable.js
The Immutable.js library is used to create immutable maps. It provides a functional programming interface for creating and manipulating immutable data structures.
Special JS Feature or Syntax: None
There are no special JavaScript features or syntax used in this benchmark.
Other Alternatives
If you're interested in exploring alternative data structures, you might consider:
Keep in mind that the choice of data structure ultimately depends on the requirements of your project.