var map = new Map()
for (let i = 0; i < 10000; i++) {
if( map.size > 5000) {
map = new Map()
}
map.set(i, Math.random())
}
var map = new Map()
for (let i = 0; i < 10000; i++) {
map.set(i, Math.random())
}
if( map.size > 5000) {
map = new Map()
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
check each time | |
check once |
Test name | Executions per second |
---|---|
check each time | 505.9 Ops/sec |
check once | 506.0 Ops/sec |
What is being tested?
MeasureThat.net is testing the performance of JavaScript's Map
data structure, specifically how it handles resizing and adding elements. The benchmark defines two test cases:
Map
every 5000 iterations.Map
with 10000 elements and then checks its size.Options compared
The two test cases compare the performance of creating and resizing a Map
:
Map
every 5000 iterations.Map
with 10000 elements.Pros and cons of each approach
Map
every 5000 iterations, which can be beneficial for systems with limited memory.Map
and checking its size.Map
is used for 10000 iterations.Library and purpose
There is no library explicitly mentioned in the benchmark definition. However, JavaScript's built-in Map
data structure is being tested.
Special JS feature or syntax
None are mentioned specifically.
Other alternatives
To measure the performance of Map
, other approaches could be considered:
Object.assign()
to resize: Instead of creating a new Map
, you could create an array and use Object.assign()
to add elements, resizing the array as needed.Map
using different libraries or frameworks, such as React or Angular, to see how they optimize and handle resizing.Keep in mind that these alternatives would require modifying the benchmark definition and may not directly compare to the original test cases.