var array = [];
var iarray = new Int32Array(100);
var map = new Map();
for (let i = 0; i < 100; i++) {
array.push(i);
iarray[i] = i;
map.set(i, i);
}
for(let i = 0; i < 100; i++){
array[i] = array[i] + 1;
if(i == 50) break;
}
for(let i = 0; i < 100; i++){
iarray[i] = iarray[i] + 1;
if(i == 50) break;
}
for(let i = 0; i < 100; i++){
map.set(i, map.get(i) + 1);
if(i == 50) break;
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
array | |
int32array | |
map |
Test name | Executions per second |
---|---|
array | 32544928.0 Ops/sec |
int32array | 47834236.0 Ops/sec |
map | 3625482.8 Ops/sec |
Benchmark Overview
The provided JSON represents a JavaScript microbenchmark test case on the MeasureThat.net website. The benchmark compares the performance of three data structures: arrays, Int32Array objects, and Map instances.
Tested Options and Their Pros/Cons
push
and indexing operations.uint8ClampedValue
and indexing operations.set
and get
operations.Library Usage
The test case uses the following libraries:
Both of these libraries are part of the JavaScript Standard Library and have good support across browsers and platforms.
Special JS Features
There are no special JavaScript features or syntax used in this benchmark.
Other Considerations
When choosing a data structure for performance-critical code, consider the trade-offs between simplicity, support, and performance. Int32Array objects can offer better performance than traditional arrays, but their limited browser support may be a concern. Maps can provide fast performance, but they might incur higher overhead due to hash table management.
Alternative Data Structures
Other data structures that could be compared in this benchmark include:
Keep in mind that the choice of data structure ultimately depends on the specific use case and requirements of the application.