Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map vs Object GetAndSet largeset
(version: 0)
Lookup and set of map vs object for large set
Comparing performance of:
Map lookup vs Obj lookup
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var map = new Map(); var obj = {}; map.set('a', 5); obj['a'] = 5; var i = 0, count = 20000, a;
Tests:
Map lookup
let x; for (i = 0; i < count; i++) { map.set('a'+i, i); } for (i = 0; i < count; i++) { x=map.get('a'+i); }
Obj lookup
let y; for (i = 0; i < count; i++) { obj['a'+i]=i; } for (i = 0; i < count; i++) { y=obj['a'+i]; }
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Map lookup
137.8 Ops/sec
Obj lookup
92.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON benchmark definition and test cases. **Benchmark Definition** The website MeasureThat.net allows users to create and run JavaScript microbenchmarks. The provided JSON represents a benchmark for comparing the performance of Map and Object get-and-set operations on large sets. **What is tested?** The benchmark tests two scenarios: 1. `Map lookup`: This scenario creates a new Map object and sets its keys with values from 0 to count-1 (20000). Then, it retrieves these values using the `get()` method and stores them in an array (`x`). 2. `Obj lookup`: Similar to the first scenario, but uses an Object instead of a Map. The values are set on the object's keys using dot notation (`obj['a'+i]=i`) and retrieved using the dot notation as well (`y=obj['a'+i]`). **Options compared** The two options being compared are: * Map (using `Map` constructor) * Object (using literal syntax or dot notation) These options have different pros and cons: **Map:** Pros: * Efficient for large datasets, as it uses a hash table to store key-value pairs. * Can be more memory-efficient than objects when dealing with large amounts of data. Cons: * May require additional overhead due to the implementation of the `Map` constructor. * Some older browsers might not support Map. **Object:** Pros: * More widely supported across browsers and platforms. * Easier to use for simple key-value pairs, as it's a more familiar syntax. Cons: * Less efficient than Map for large datasets, due to slower lookup times and increased memory usage. * May lead to more memory overhead compared to Maps when dealing with large amounts of data. **Other considerations** When running these benchmarks, it's essential to consider factors such as: * Browser version and platform support * JavaScript engine optimization (e.g., Just-In-Time compilation) * Cache behavior and reuse **Library and purpose** The `Map` constructor is a built-in JavaScript object that provides an efficient way to store key-value pairs. It's designed to handle large amounts of data, making it suitable for this benchmark. **Special JS feature or syntax** There are no special features or syntax mentioned in the provided JSON benchmarks. However, keep in mind that MeasureThat.net might use other features, such as Web Workers or WebAssembly, to optimize performance. If you're interested in exploring these options, please refer to the website's documentation for more information. **Alternatives** If you're looking for alternative benchmarking tools or approaches, consider: * Node.js built-in `bench` module: Offers a simple way to create and run benchmarks on Node.js. * BenchmarkJS: A popular benchmarking library for JavaScript that provides more advanced features and customization options. * Benchmarking frameworks like Benchmarkist or Benchmark-it: Can help you create and compare benchmarks in your own projects. Feel free to ask if you have any further questions!
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
Object.fromEntries vs Map
Comments
Confirm delete:
Do you really want to delete benchmark?