Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map vs Object - the real test
(version: 19)
Lookup of map vs object
Comparing performance of:
Map lookup vs Obj lookup vs Map set vs Obj set vs hasOwnProperty vs has vs delete vs remove vs array lookup
Created:
4 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var map1 = new Map(); var obj1 = {}; map1.set(0, 5); obj1[0] = 5; var map2 = new Map(); var obj2 = {}; var arrString = []; for (var i = 0; i < 10000000; i++) { arrString.push(i); } var arr = [1,2,3,null,5]; var a = 0, b = 0, c = 0, d = 0;
Tests:
Map lookup
map1.get('aaa');
Obj lookup
obj1['aaa'];
Map set
map2.set(arrString[a++], 1);
Obj set
obj2[arrString[b++]] = 1;
hasOwnProperty
obj1.hasOwnProperty('aaa');
has
map1.has('aaa');
delete
delete obj2[arrString[c++]];
remove
map2.delete(arrString[d++]);
array lookup
arr[2]
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (9)
Previous results
Fork
Test case name
Result
Map lookup
Obj lookup
Map set
Obj set
hasOwnProperty
has
delete
remove
array 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 benchmark JSON and explain what's being tested, the options compared, their pros and cons, and other considerations. **Benchmark Definition** The benchmark definition represents a JavaScript microbenchmark that tests the performance of various methods on objects and maps. * `map1` and `obj1` are objects (JavaScript native data type) created using the `{}` syntax. * `map2` is a Map object (a built-in JavaScript data structure), and `arrString` is an array filled with 10,000,000 indices from 0 to 9,999,999. **Options Compared** The benchmark compares the performance of various methods: 1. **Map Lookup (`map1.get('aaa')`) vs Object Lookup (`obj1['aaa']`) * Pros: + Both are relatively fast and efficient. * Cons: + `get()` method may be slower due to additional checks (e.g., key existence). 2. **Map Set (`map2.set(arrString[a++], 1)`) vs Object Set (`obj2[arrString[b++]] = 1`) * Pros: + Both are efficient, but the Map set may be slightly faster due to its optimized implementation. 3. **hasOwnProperty()` (Object method) vs `has()` (Map method) * Pros: + Both methods are fast and provide similar performance. 4. **delete` (`delete obj2[arrString[c++]]`) vs `remove()` (Map method) * Pros: + Both methods are efficient, but the `remove()` method may be slightly faster due to its optimized implementation. 5. **Array Lookup (`arr[2]`) * Pros: + Relatively fast and efficient. **Other Considerations** * The benchmark uses a large array `arrString` filled with 10,000,000 indices from 0 to 9,999,999. This is done to test the performance of each method under heavy loads. * Both Map and object implementations use JavaScript's built-in equality checks for key existence. **Library** None mentioned in this benchmark definition. No special JavaScript features or syntax used in this benchmark. **Alternatives** For similar microbenchmarks, consider: 1. jsPerf (discontinued) 2. Benchmark.js 3. Microbenchmarking libraries like fast-benchmark or benchmark-chromium Keep in mind that different benchmarks may prioritize specific use cases or optimizations, so it's essential to choose the right tool for your needs. This analysis should provide a good starting point for understanding this benchmark and its performance characteristics. If you have more questions or need further clarification, feel free to ask!
Related benchmarks:
Foreach&Push vs Map2
iterating from a filled object VS iterating from a map
array includes vs object key lookup, large arrays
Array vs Class
Map.forEach vs Array.forEach vs Array.from(Map.prototype.values()).forEach
Comments
Confirm delete:
Do you really want to delete benchmark?