Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Sparse Array Vs. Object, Map, Set, Number Indexes vs alpha indexes
(version: 0)
Comparing performance of:
Object vs Array vs Set Length Array vs TypedArray vs map vs set vs Object Alpha index vs Array numeric index
Created:
2 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var iterations =10000; var step = 10;
Tests:
Object
const obj = {}; for(let i=0;i<iterations;i+=step){ obj[i]= i; obj[i+1]=obj[i]+1; }
Array
const arr = []; for(let i=0;i<iterations;i+=step){ arr[i]=i; arr[i+1]= arr[i]+1; }
Set Length Array
const setLengthArr = new Array(iterations); for(let i=0;i<iterations;i+=step){ setLengthArr[i]=i; setLengthArr[i+1] = setLengthArr[i]+1; }
TypedArray
const typedArray = new Uint32Array(iterations); for(let i=0;i<iterations;i+=step){ typedArray[i]=i; typedArray[i+1]= typedArray[i]+1; }
map
const map = new Map(); for(let i=0;i<iterations;i+=step){ map.set(i,i); map.set(i+1,map.get(i)+1) }
set
const set = new Set(); for(let i=0;i<iterations;i+=step){ set.add(i); set.add(set.has(i) && i) }
Object Alpha index
const obj = {}; for(let i=0;i<iterations;i+=step){ const val = 'a' + i; obj[val]= val; obj[i+1]=obj[val]; }
Array numeric index
const arr = []; for(let i=0;i<iterations;i+=step){ const val = 'a' + i; arr[i]= val; arr[i+1]=arr[i]; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (8)
Previous results
Fork
Test case name
Result
Object
Array
Set Length Array
TypedArray
map
set
Object Alpha index
Array numeric index
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 benchmarks! **Benchmark Overview** The provided benchmark tests various data structures in JavaScript: objects, arrays, set length arrays, typed arrays, maps, sets, and even object alpha indexing. The test cases aim to measure the performance of each data structure by iterating over a large number of elements (10000) with a step size of 10. **Options Compared** The benchmark compares several options: 1. **Objects**: Direct objects are used as the testing ground for iterative operations. 2. **Arrays**: Native JavaScript arrays are tested. 3. **Set Length Arrays**: A custom array is created with a fixed length, similar to a native array but not initialized. 4. **TypedArrays**: Typed arrays (Uint32Array in this case) are used for performance-critical operations. 5. **Maps**: Maps are used as the testing ground for iterative key-value pairs. 6. **Sets**: Sets are used for fast membership tests and additions. **Pros and Cons** Here's a brief summary of each data structure's strengths and weaknesses: * **Objects**: Pros: flexible, easy to use; Cons: slow indexing, large overhead for large datasets. * **Arrays**: Pros: efficient, fast indexing; Cons: requires explicit size management. * **Set Length Arrays** and **TypedArrays**: Pros: efficient, low overhead; Cons: require manual memory management and are less flexible than native arrays or objects. * **Maps**: Pros: fast membership tests, efficient key-value pairs; Cons: less intuitive than other data structures for simple iterative operations. * **Sets**: Pros: fast membership tests, efficient add/remove operations; Cons: less suitable for complex data storage. **Performance Comparison** The benchmark results show that: 1. Set Length Arrays and TypedArrays perform significantly better than native arrays due to their low overhead and efficient memory management. 2. Maps outperform objects in most cases, thanks to their optimized membership tests and key-value pair operations. 3. Sets are generally fast but may be less suitable for complex data storage scenarios. 4. Objects remain a viable option for simple iterative operations, despite being slower than other alternatives. **Object Alpha Indexing** The Object Alpha Indexing test case uses an object with a large number of keys to measure its performance. The results show that this approach is still relatively slow compared to other data structures. In summary, the benchmark provides valuable insights into the relative performance of different JavaScript data structures. When choosing a data structure for your use case, consider factors such as efficiency, flexibility, and memory management requirements.
Related benchmarks:
Array construct vs array push
Reduce Push vs. flatMap
Array fill method vs push in for loop
Reduce Push vs. flatMap with subarrays
Array.from() vs new Array() vs push
Comments
Confirm delete:
Do you really want to delete benchmark?