Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map vs Object Extended
(version: 0)
Lookup of map vs object
Comparing performance of:
Map lookup vs Obj lookup
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var map = new Map(); var obj = {}; for (i = 0; i < 10000; i++) { map.set(i, i); obj[i] = i; } var i = 0, count = 1000, result;
Tests:
Map lookup
for (i = 0; i < count; i++) { a = map.get(i*10); }
Obj lookup
for (i = 0; i < count; i++) { a = obj[i*10]; }
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:
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 break down the provided JSON data and explain what is tested on the website. **Benchmark Definition** The benchmark definition represents a JavaScript test case that compares the performance of two data structures: Maps (JavaScript's built-in `Map` object) and objects with an extended prototype chain. The script preparation code initializes two instances, `map` and `obj`, and populates them with 10,000 key-value pairs using nested loops. **Script Preparation Code** ```javascript var map = new Map(); var obj = {}; for (i = 0; i < 10000; i++) { map.set(i, i); obj[i] = i; } ``` This code creates a `Map` object and an object literal (`obj`) with the same key-value pairs. **Options Compared** The benchmark compares two options: 1. **Maps (JavaScript's built-in `Map` object)** * Pros: + Efficient lookups, as Maps use hash tables for storage. + Supports advanced methods like `set()`, `get()`, and `has()`. * Cons: + May have additional memory overhead due to the hash table structure. 2. **Objects with an extended prototype chain** * Pros: + Can be faster for certain operations, as objects can inherit properties from parent prototypes. * Cons: + Lookups can be slower due to the need to traverse the prototype chain. **Library** There is no external library used in this benchmark. The `Map` object is a built-in JavaScript feature. **Special JS Feature/Syntax** None of the code snippets use any special JavaScript features or syntax beyond what's standard in modern JavaScript (ES6+). **Other Alternatives** In addition to Maps and objects with an extended prototype chain, other data structures that could be used for this benchmark include: * Arrays with indexing * Custom object implementations using a different data structure (e.g., binary search trees) * Other specialized data structures like hash tables or trie data structures Keep in mind that the performance difference between these alternatives might be negligible, and the benchmark's results may not generalize to other scenarios. **Benchmark Preparation Code** The provided `Script Preparation Code` initializes two instances, `map` and `obj`, with 10,000 key-value pairs using nested loops. The `Html Preparation Code` is empty (`null`), indicating that no additional HTML-related setup is required for this benchmark.
Related benchmarks:
Array from() vs Map.keys()
Array from() vs Map.keys() vs Map.values() vs spread
Array from() vs Map.keys() vs Map.values() vs spread (fixed)
array includes vs object key lookup, large arrays
Map.forEach vs Array.forEach vs Array.from(Map.prototype.values()).forEach
Comments
Confirm delete:
Do you really want to delete benchmark?