Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map vs Object2020
(version: 0)
Lookup of map vs object
Comparing performance of:
Map lookup vs Obj lookup vs Map deletion vs object deletion
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var map = new Map(); var obj = {}; map.set(`${i}_a`, 5); obj[`${i}_a`] = 5; var i = 0, count = 1000, a;
Tests:
Map lookup
for (i = 0; i < count; i++) { a = map.get(`${i}_a`); }
Obj lookup
for (i = 0; i < count; i++) { a = obj[`${i}_a`]; }
Map deletion
for (i = 0; i < count; i++) { a = map.delete(`${i}_a`); }
object deletion
for (i = 0; i < count; i++) { obj[`${i}_a`] = undefined; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Map lookup
Obj lookup
Map deletion
object deletion
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 explaining the benchmark. **What is being tested?** MeasureThat.net is testing the performance of two data structures: Maps and Objects, in JavaScript. Specifically, it's comparing their lookup, deletion, and assignment operations. **Options compared:** The benchmark compares four test cases: 1. **Map Lookup**: This test case iterates over a Map object and retrieves values using `map.get()` for each key. 2. **Object Lookup**: This test case iterates over an Object literal and accesses values using the property name as a string (`obj[`${i}_a`]`) for each key. 3. **Map Deletion**: This test case iterates over a Map object and deletes values using `map.delete()` for each key. 4. **Object Deletion**: This test case iterates over an Object literal and sets the value to undefined (`obj[`${i}_a`] = undefined`) for each key. **Pros and Cons:** 1. **Map Lookup**: * Pros: Maps are designed for fast lookups, making this operation efficient. * Cons: This test assumes that Map keys are unique, which may not always be the case in real-world scenarios. 2. **Object Lookup**: * Pros: Objects can be used as maps with string keys, providing a similar performance profile to Maps. * Cons: Object property names are strings, which can lead to slower lookups compared to Map keys. 3. **Map Deletion**: * Pros: Map keys are unique and don't need to be explicitly deleted, reducing overhead. * Cons: This test only deletes values and not the entire key-value pair, which may affect performance. 4. **Object Deletion**: * Pros: This test deletes the value and doesn't rely on string property names, making it a good comparison. * Cons: Object property names can lead to slower lookups and deletions compared to Map keys. **Library and its purpose:** The benchmark uses the built-in `Map` and `Object` data structures in JavaScript. These are core data structures provided by the language, designed for efficient storage and manipulation of key-value pairs. **Special JS feature or syntax:** There is no special JS feature or syntax used in this benchmark that's not already explained above. **Other alternatives:** If you want to test other data structures or libraries, here are some alternatives: * **Arrays**: You can create an array with unique values and perform lookup, deletion, and assignment operations. * **Sparse arrays**: An array with only a subset of keys set to specific values can be used to compare performance with Maps. * **Third-party libraries**: Libraries like Lodash or Ramda provide additional data structures and utility functions that you can use for benchmarking. Keep in mind that these alternatives may change the benchmark's results, as each library has its own strengths and weaknesses.
Related benchmarks:
Map vs Object2
Map vs Object part 2
Map vs Object part 3
Map vs Object read performance for a 1000 key lookup
Comments
Confirm delete:
Do you really want to delete benchmark?