Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Benchmark Name test
(version: 0)
Comparing performance of:
obj vs New map
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var keyCount = 14 var map = new Map() var obj = {} // Hide lookup keys to prevent V8 cheating (AKA Optimizing) var getConspicuousKey = seed => keys[Math.floor(seed * keyCount)]
Tests:
obj
for (let i=0; i<keyCount; i++) { let val = Math.random() let key = Math.random() map.set(key,val) }
New map
for (let i=0; i<keyCount; i++) { let val = Math.random() let key = Math.random() obj[key] = val }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
obj
New map
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):
I'd be happy to explain the provided benchmark. **What is being tested?** The benchmark measures the performance of JavaScript engines (specifically, V8) in two different scenarios: 1. **Insertion into an object**: The first test case (`"obj"``) creates a random key-value pair for each iteration in a `for` loop. It uses a `Map` data structure to store the values and inserts them into an empty object (`obj`) as keys. 2. **Insertion into a new Map**: The second test case (`"New map"``) does the same thing, but instead of using an existing object, it creates a new `Map` instance and inserts key-value pairs directly into it. **Options compared** The benchmark compares two approaches: 1. **Using an object as a container**: In both test cases, the JavaScript engine is forced to insert values into either an existing object (`obj`) or a new Map instance. 2. **No optimization**: The benchmark assumes that the engine should perform the insertion operation for each key-value pair. **Pros and Cons of different approaches** 1. **Using an object as a container**: * Pros: This approach is more representative of real-world use cases, where objects are often used to store data. * Cons: V8 might optimize this approach by reusing existing object properties or using caching mechanisms, which could affect the benchmark results. 2. **No optimization**: This approach allows the engine to perform the insertion operation without any optimizations. **Libraries and features** None of the test cases explicitly use a library or special JavaScript feature. The only notable aspect is the use of `Map` data structure in both test cases, which is a built-in JavaScript object since ECMAScript 2015 (ES6). **Other considerations** 1. **V8 Optimizations**: V8 has various optimization mechanisms that might affect the benchmark results. For example, it can reuse existing object properties or use caching to reduce memory allocation and deallocation. 2. **Cache locality**: The benchmark's use of random keys and values may not accurately reflect real-world scenarios where cache locality is important. 3. **Hardware factors**: The benchmark doesn't account for hardware-specific factors that could impact performance, such as CPU frequency, cache sizes, or thread scheduling. **Alternatives** Other benchmarks might test similar scenarios with different variations, such as: 1. Using a different data structure (e.g., `Array` instead of `Map`) 2. Inserting values into an array or other data structures 3. Adding more complex operations (e.g., sorting, searching) to the benchmark Keep in mind that these alternatives would require modifications to the benchmark setup and test cases to ensure they remain relevant and accurate.
Related benchmarks:
Map vs Object (real-world) Performance 2
Map vs Object (real-world) Performance (lookup and set)
Map vs Object (real-world) Performance (disabling object-specific optimizations and default keys)
Map vs Object (real-world) Performance (better) 2
Map vs Object (real-world) Performance (non-numeric key)
Comments
Confirm delete:
Do you really want to delete benchmark?