Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map vs Object: Full benchmark
(version: 0)
Lookup of map vs object
Comparing performance of:
Map Write vs Object Write vs Map Read vs Object Read
Created:
4 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var mapWrite = new Map(); var objWrite = {}; var mapRead = new Map(); var objRead = {}; var read = 'a'; mapRead.set(read, read); objRead[read] = read; var count = 1000;
Tests:
Map Write
for (i = 0; i < count; i++) { mapWrite.set(i, i); };
Object Write
for (i = 0; i < count; i++) { objWrite[i] = i; };
Map Read
for (i = 0; i < count; i++) { mapRead.get(read); };
Object Read
for (i = 0; i < count; i++) { objRead[read]; };
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Map Write
Object Write
Map Read
Object Read
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Safari/605.1.15
Browser/OS:
Safari 17 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Map Write
16289.3 Ops/sec
Object Write
18942.6 Ops/sec
Map Read
12807.9 Ops/sec
Object Read
12781.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its test cases. **Benchmark Overview** The benchmark, named "Map vs Object: Full benchmark", compares the performance of two data structures in JavaScript: Maps (also known as hash maps) and objects. A Map is an unordered collection of key-value pairs, while an object is a collection of properties with values. The benchmark tests the write and read operations on both data structures. **Test Cases** There are four test cases: 1. **Map Write**: This test case measures the time it takes to write 1000 key-value pairs into a Map. 2. **Object Write**: This test case measures the time it takes to write 1000 key-value pairs into an object. 3. **Map Read**: This test case measures the time it takes to read 1000 values from a Map using the `get()` method. 4. **Object Read**: This test case measures the time it takes to read 1000 values from an object using the `[]` syntax (i.e., accessing properties directly). **Options Compared** The benchmark compares the performance of two approaches: * Using Maps for both write and read operations * Using objects for both write and read operations **Pros and Cons of Each Approach** **Maps:** Pros: * Fast lookups: Maps use a hash table, which provides fast lookup times (O(1) average case). * Efficient insertion and deletion: Maps can insert or delete elements quickly. Cons: * May require more memory due to the overhead of the hash table. * Can be slower for very large datasets if the hash function is poorly implemented. **Objects:** Pros: * Lightweight: Objects are typically smaller in memory compared to Maps. * Simple and intuitive API. Cons: * Slower lookups: Object lookups can be O(n) in the worst case (linear search). * Insertion and deletion can be slower than for Maps. **Library Used** The benchmark uses the built-in `Map` and `Object` data structures in JavaScript. The `Map` object provides a hash table-like interface, while the `Object` object provides a simple key-value pair interface. **Special JS Features or Syntax** None are explicitly mentioned, but note that some browsers may have extensions or patches that affect the performance of these tests. Additionally, the use of `for (i = 0; i < count; i++)` loops is a common pattern in benchmarking and provides an efficient way to iterate over large numbers of iterations. **Other Alternatives** Some alternative approaches to measuring performance could include: * Using a profiler or benchmarking tool that provides more detailed information about CPU utilization, memory usage, and other metrics. * Comparing the performance of different JavaScript engines or virtual machines (e.g., V8, SpiderMonkey). * Testing with larger datasets or more complex operations (e.g., insertion/deletion of elements, sorting, etc.). Keep in mind that these alternatives may require additional setup, configuration, or expertise to execute effectively.
Related benchmarks:
iterating from a filled object VS iterating from a map
Array from() vs Map.keys()
Map vs Object read performance for a 1000 key lookup
new Map vs set array to map
Object.fromEntries vs Map
Comments
Confirm delete:
Do you really want to delete benchmark?