Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
map vs obj test4
(version: 0)
Comparing performance of:
map vs obj
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var map = new Map(); var obj = {}; var value = { toto: 'name', toto: { toto: 'name', toto: { toto: 'name', }, }, toto: { toto: 'name', toto: { toto: 'name', }, }, toto: { toto: 'name', toto: { toto: 'name', }, }, } for (i = 0; i < 2000; i++) { map.set(i, value); obj[i] = value }
Tests:
map
map.get(991)
obj
obj[991]
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
map
obj
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Browser/OS:
Chrome 143 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
map
169054240.0 Ops/sec
obj
165297616.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark definition and explain what's being tested, compared, and their pros and cons. **Benchmark Definition** The provided JSON defines two individual test cases: 1. `map.get(991)` ( Test Name: "map" ) 2. `obj[991]` ( Test Name: "obj" ) These tests are designed to measure the performance of accessing elements in a `Map` data structure versus an object. **Script Preparation Code** The script preparation code is identical for both test cases: ```javascript var map = new Map(); var obj = {}; var value = { toto: 'name', toto: { toto: 'name', toto: { toto: 'name', }, }, toto: { toto: 'name', toto: { toto: 'name', }, }, toto: { toto: 'name', toto: { toto: 'name', }, }, }; ``` This code creates a `Map` called `map`, an object called `obj`, and a nested object `value`. The nested object is populated with multiple levels of nesting, which will be accessed in the tests. **Html Preparation Code** There is no HTML preparation code provided for this benchmark. **Comparison** The two test cases compare the performance of accessing elements in a `Map` data structure (`map.get(991)`) versus an object (`obj[991]`). The execution speed and number of executions per second are measured for both tests. **Pros and Cons** **`map.get(991)` (Test Name: "map")** Pros: * Fast lookups due to the use of a hash table * Efficient access to nested elements in the `value` object Cons: * May have higher overhead due to the creation of a new Map instance and the associated memory allocation **`obj[991]` (Test Name: "obj")** Pros: * May be faster due to the use of an existing object instance * Less overhead compared to creating a new Map instance Cons: * May be slower due to the need to traverse the nested object structure * Less efficient access to elements in deep nesting **Library and Purpose** The `Map` data structure is built into modern JavaScript engines, including Firefox. It provides a fast and efficient way to store key-value pairs. **Special JS Feature or Syntax** There are no special features or syntax used in this benchmark that would require specific knowledge of JavaScript. The focus is on comparing the performance of accessing elements in a `Map` versus an object. **Alternatives** Other alternatives for storing and retrieving data include: * Arrays: While not as efficient as Maps, arrays can be used to store key-value pairs. * Objects with property names: Similar to using objects, but with the added complexity of having multiple property names. * JSON files or other external storage: For larger datasets or more complex data structures. Keep in mind that the choice of data structure depends on the specific use case and performance requirements.
Related benchmarks:
Object spread vs New map
Object spread vs New map with string keys
Object spread vs new Map with complex data
Object spread vs New map entries
Object spread vs new Map vs Object assign with complex data
Comments
Confirm delete:
Do you really want to delete benchmark?