Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Dynamic Set vs Object vs Map
(version: 0)
Comparing performance of:
Set vs Object vs Map
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
Set
const data = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]; var set = new Set(); data.forEach((item) => set.add(item));
Object
const data = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]; var set = {}; data.forEach((item) => set[item] = true);
Map
const data = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]; var set = new Map(); data.forEach((item) => set.set(item, true));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Set
Object
Map
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/129.0.0.0 Safari/537.36
Browser/OS:
Chrome 129 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Set
3109691.5 Ops/sec
Object
8209022.0 Ops/sec
Map
2983438.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview** The provided JSON represents a benchmark test on MeasureThat.net, which compares the performance of three data structures in JavaScript: Sets, Objects, and Maps. The goal is to determine which data structure is most efficient for storing unique values. **Data Structures Compared** 1. **Sets**: A Set is an unordered collection of unique values, designed to store only unique elements. 2. **Objects**: An Object is a mutable data type that stores key-value pairs. 3. **Maps**: A Map is an ordered collection of key-value pairs, similar to an Object, but with a specific order. **Options Compared** The benchmark tests the performance of each data structure in the following scenarios: * Creating and populating a Set, Object, or Map with 10 unique values using `forEach`. * Adding elements to each data structure using `add` (Set), bracket notation (Object), or `set` (Map). **Pros and Cons** * **Sets**: Pros: + Fast lookup times (~ O(1)). + Efficient for storing unique values. + Does not allow duplicate values, which can reduce memory usage. * Cons: + Not ordered, so indexing might be slow. + May require additional checks to verify uniqueness. * **Objects**: Pros: + Supports all standard JavaScript data types (numbers, strings, booleans). + Can store arbitrary key-value pairs. + Allows duplicate values if not properly validated. * Cons: + Lookups are slower (~ O(n)) compared to Sets. + May consume more memory due to the presence of duplicate values. * **Maps**: Pros: + Supports ordered key-value pairs, which can improve indexing performance. + Similar lookup times as Objects (~ O(n)). + Does not allow duplicate keys (unless using a specific implementation). **Library and Purpose** None explicitly mentioned in the benchmark. **Special JS Features or Syntax** None mentioned. **Other Considerations** * The benchmark does not account for other factors that might affect performance, such as array size, data distribution, or algorithmic complexity. * It is essential to consider the trade-offs between these data structures when choosing one for a specific use case. **Alternatives** If you need alternative data structures in JavaScript, consider: 1. **Arrays**: A contiguous collection of values with indexing support. 2. **WeakSets**: An unordered collection of unique values that allows deletion of elements without affecting uniqueness. 3. **WeakMaps**: An ordered collection of key-value pairs that allows deletion of keys without affecting order. Note: WeakSets and WeakMaps are designed to avoid memory leaks when deleting objects from the data structure, but they may not be as efficient as Sets, Objects, or Maps in certain scenarios.
Related benchmarks:
Create Map/Set vs reuse Map/Set
Map.set vs Object assign
Map sets vs gets
Array Spread vs Fill vs New Array
Object.fromEntries vs Map
Comments
Confirm delete:
Do you really want to delete benchmark?