Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map vs Object with 10k elements
(version: 0)
Lookup of map vs object
Comparing performance of:
Map lookup vs Obj lookup
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var map = new Map(); var obj = {}; for(let i = 0; i < 10000; i++) { map.set(i, 5); obj[i] = 5; } var i = 0, count = 1000, a;
Tests:
Map lookup
for (i = 0; i < count; i++) { a = map.get('a'); }
Obj lookup
for (i = 0; i < count; i++) { a = obj['a']; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Map lookup
Obj lookup
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0
Browser/OS:
Firefox 133 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Map lookup
296927.6 Ops/sec
Obj lookup
325302.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark JSON and explain what's being tested, compared, and other considerations. **Benchmark Definition** The benchmark is called "Map vs Object with 10k elements". It measures the performance of looking up values in a `Map` data structure versus an object (`obj`) with 10,000 elements. The script preparation code initializes two data structures: a `Map` named `map` and an object `obj`, both populated with 10,000 key-value pairs. **Options Compared** Two approaches are being compared: 1. **Object Lookup (Obj lookup)**: This involves using the bracket notation (`obj['a']`) to access values in the `obj` object. 2. **Map Lookup (Map lookup)**: This involves using the `get()` method of the `Map` data structure to retrieve values associated with a given key. **Pros and Cons** * **Object Lookup (Obj lookup)**: + Pros: Easy to implement, widely supported by most browsers. + Cons: May incur overhead due to string parsing and lookup in the object's internal hash table. * **Map Lookup (Map lookup)**: + Pros: Efficient for large datasets, as it uses a hash table for fast lookups. + Cons: Less intuitive than bracket notation, may not be supported by older browsers. **Library Used** The `Map` data structure is implemented in JavaScript, and its purpose is to provide an efficient way to store and retrieve key-value pairs. In this benchmark, the `Map` data structure is used to represent a collection of key-value pairs, allowing for fast lookups using the `get()` method. **Special JS Feature/Syntax** None are explicitly mentioned in this benchmark. However, it's worth noting that JavaScript has several features and syntax elements that can affect performance, such as: * Closures: Can create optimization overhead. * Function expressions vs. declarations: Can have different execution plans. * Hoisting: Can lead to unexpected behavior. **Other Considerations** This benchmark assumes a modern JavaScript engine with good support for `Map` data structures. It's likely that the results would vary across different browsers, as some may not support or optimize `Map` lookups as well. For alternative approaches, you could consider: * Using an array and indexing into it (e.g., `arr[index]`) instead of objects and bracket notation. * Comparing performance with other data structures like `Set`, `WeakMap`, or even arrays with binary search. * Adding more test cases to evaluate the performance of other operations, such as inserting, deleting, or iterating over elements in both `Map` and object data structures.
Related benchmarks:
iterating from a filled object VS iterating from a map
Array from() vs Map.keys()
array includes vs object key lookup, large arrays
Map vs Object read performance for a 1000 key lookup
Map.forEach vs Array.forEach vs Array.from(Map.prototype.values()).forEach
Comments
Confirm delete:
Do you really want to delete benchmark?