Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
creating maps vs creating objects
(version: 0)
Comparing performance of:
creating maps vs creating objects
Created:
one year ago
by:
Registered User
Go to the latest result
Tests:
creating maps
for (let i = 0; i < 1000; ++i) { const map = new Map() map.set(i + "", i) }
creating objects
for (let i = 0; i < 1000; ++i) { const obj = {} obj[i + ""] = i }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
creating maps
creating objects
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 128 on Android
View result in a separate tab
Embed
Embed Benchmark Result
creating maps
3K/s
creating objects
423/s
View exact numbers
Test name
Executions per second
✓
creating maps
2,703 Ops/sec
creating objects
423 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what is being tested in this benchmark. **Benchmark Definition:** The benchmark compares two approaches to create JavaScript objects: 1. **Creating Maps**: The script creates a new Map instance and sets an entry with the key as a string concatenation of `i` and `"}`, where `i` is an integer from 0 to 999. 2. **Creating Objects**: The script creates an empty object `{}` and sets a property with the key as a string concatenation of `i` and `"}`, where `i` is an integer from 0 to 999. **Options Compared:** The benchmark compares the performance of these two approaches: * Creating Maps (using JavaScript's built-in Map data structure) * Creating Objects (using plain JavaScript objects) **Pros and Cons of Each Approach:** * **Creating Maps**: This approach uses a hash table, which provides fast lookups, insertions, and deletions. However, it may have a higher memory overhead due to the use of an object with specific keys. * **Creating Objects**: This approach creates a plain JavaScript object, which can be less efficient for large datasets since objects are inherently slower than hash tables. However, it can be more flexible and easier to work with. **Considerations:** * The benchmark measures the execution speed, which is likely influenced by factors such as caching, memoization, or other performance optimization techniques. * The script concatenates strings using `" + "` for string interpolation, which may lead to slower performance compared to modern JavaScript's template literals (`${expression}`). **Library or Built-in Feature Used:** None of the benchmark uses any external libraries. It only relies on built-in JavaScript features. **Special JS Feature or Syntax:** The benchmark uses string concatenation using `" + "` for string interpolation, which is a relatively old syntax in modern JavaScript. While it's still supported for compatibility reasons, more recent versions of JavaScript might use template literals (`${expression}`) instead. **Other Alternatives:** If you want to explore alternative approaches or optimize the existing ones, here are some additional options: * Using `Object.assign()` to create objects could be another approach. * Creating arrays with the same properties as the Map and then iterating over it might provide similar performance. * Utilizing modern JavaScript's `Map.prototype.set()` methods for better cache locality. Keep in mind that these alternatives may require modifications to your benchmark script, which is outside the scope of this explanation.
Related benchmarks
Array.prototype.map vs Lodash map
flatMap vs map/flat
new Map vs set array to map
Array Spread vs Fill vs New Array
Object.fromEntries vs Map
Comments
Confirm delete:
Do you really want to delete benchmark?