Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Objects vs Maps longer test
(version: 1)
Comparing performance of:
Object Insertion vs Map insertion vs Object Insertion Overwrites vs Map insertion overwrites vs Object simulated usage vs Map simulated usage
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var map = new Map(); var obj = {}; var iterations = 1000000; var tenthOfIterations = iterations / 10;
Tests:
Object Insertion
for (let i = 0; i < iterations; i++) { obj[i] = i; }
Map insertion
for (let i = 0; i < iterations; i++) { map.set(i, i); }
Object Insertion Overwrites
for (let i = 0; i < iterations; i++) { obj[i % 10] = i; }
Map insertion overwrites
for (let i = 0; i < iterations; i++) { map.set(i % 10, i); }
Object simulated usage
for (let i = 0; i < iterations; i++) { obj[i] = i; } for (let i = 0; i < iterations; i++) { obj[i % 10] = obj[i]; } for (let i = 0; i < tenthOfIterations; i++) { delete obj[i * 10]; }
Map simulated usage
for (let i = 0; i < iterations; i++) { map.set(i, i); } for (let i = 0; i < iterations; i++) { map.set(i % 10, map.get(i)); } for (let i = 0; i < tenthOfIterations; i++) { map.delete(i * 10); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
Object Insertion
Map insertion
Object Insertion Overwrites
Map insertion overwrites
Object simulated usage
Map simulated usage
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 dive into the world of JavaScript microbenchmarks and explore what's being tested in this benchmark. **Benchmark Overview** The `Objects vs Maps longer test` is a comparison between two data structures: objects (specifically, property assignment) and maps (specifically, insertion and retrieval). The benchmark aims to measure which data structure is faster for certain types of operations. **Script Preparation Code** The script preparation code sets up two variables: 1. `map`: an empty Map object. 2. `obj`: an empty object. 3. `iterations`: a large number (1,000,000) representing the number of iterations for each benchmark case. 4. `tenthOfIterations`: one-tenth of `iterations`, used in some cases. **Html Preparation Code** There is no HTML preparation code provided, which means that the browser is left to initialize its own internal state before running the benchmarks. **Individual Test Cases** Each test case consists of a single benchmark definition and a corresponding test name. The benchmark definitions are JavaScript loops that perform various operations on `obj` or `map`. Here's what each loop does: 1. **Object Insertion**: Assigns values to object properties using property assignment (`obj[i] = i;`). 2. **Map insertion**: Inserts key-value pairs into the map using `map.set(i, i);`. 3. **Object Insertion Overwrites**: Similar to Object Insertion, but overwrites existing values using modulo arithmetic (`obj[i % 10] = i;`). 4. **Map insertion overwrites**: Similar to Map insertion, but uses modulo arithmetic to overwrite existing values (`map.set(i % 10, i);`). 5. **Object simulated usage**: Assigns values to object properties and then deletes some of them using `delete obj[i * 10];`. 6. **Map simulated usage**: Inserts key-value pairs into the map and then retrieves values from it using `map.get(i)`, while overwriting existing values with modulo arithmetic (`map.set(i % 10, map.get(i));`). **Library Usage** None of the test cases use any external libraries. **Special JS Features or Syntax** There are no special JavaScript features or syntax used in this benchmark. All operations are basic property assignments and method calls (e.g., `set`, `get`, `delete`) on native objects. **Other Alternatives** To compare the performance of objects and maps, other alternatives could include: 1. Using arrays instead of objects or maps. 2. Implementing custom data structures using JavaScript classes or prototypes. 3. Using existing libraries like Lodash or Ramda for functional programming. 4. Creating a simple in-memory database to simulate real-world data storage. Keep in mind that these alternative approaches might not be directly comparable to the original benchmark, as they may introduce additional overhead or change the nature of the operations being performed.
Related benchmarks:
iterating from a filled object VS iterating from a map
Array.forEach vs Object.keys().forEach
JavaScript Map vs. Object instantiation
Map.prototype.forEach vs Array.prototype.forEach
Map.forEach vs Array.forEach vs Array.from(Map.prototype.values()).forEach
Comments
Confirm delete:
Do you really want to delete benchmark?