Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set vs Object vs Map access
(version: 0)
Comparing performance of:
Set vs Object vs Map
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
Set
var set = new Set(["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]); set.has("one"); set.has("two"); set.has("three"); set.has("four"); set.has("five"); set.has("six"); set.has("seven"); set.has("eight"); set.has("nine"); set.has("ten");
Object
var set = {"one": true, "two": true, "three": true, "four": true, "five": true, "six": true, "seven": true, "eight": true, "nine": true, "ten": true}; set["one"]; set["two"]; set["three"]; set["four"]; set["five"]; set["six"]; set["seven"]; set["eight"]; set["nine"]; set["ten"];
Map
var set = new Map([["one", true], ["two", true], ["three", true], ["four", true], ["five", true], ["six", true], ["seven", true], ["eight", true], ["nine", true], ["ten", true]]); set.get("one"); set.get("two"); set.get("three"); set.get("four"); set.get("five"); set.get("six"); set.get("seven"); set.get("eight"); set.get("nine"); set.get("ten");
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:
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):
**Benchmark Overview** The provided benchmark 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 fast lookups. **Data Structures Compared** 1. **Sets**: A Set is an unordered collection of unique values. In this benchmark, a Set is created with 10 strings and then multiple lookups are performed using the `has()` method. 2. **Objects**: An Object is an unordered collection of key-value pairs. In this benchmark, an Object is created with 10 keys (strings) and then multiple lookups are performed using bracket notation (`set["key"]`). 3. **Maps**: A Map is an object that stores key-value pairs, but the order of the key-value pairs is not guaranteed to match the order in which they were added. In this benchmark, a Map is created with 10 key-value pairs and then multiple lookups are performed using the `get()` method. **Options Compared** The options being compared are: * **Set**: Using the `has()` method for lookups * **Object**: Using bracket notation (`set["key"]`) for lookups * **Map**: Using the `get()` method for lookups **Pros and Cons of Each Approach** 1. **Set (has())**: * Pros: Fast and efficient lookup, especially for large sets. * Cons: Not suitable for key-value pairs; only returns a boolean value (`true` or `false`) indicating whether the key is present in the set. 2. **Object (bracket notation)**: * Pros: Flexibility to access values by both keys and indices. * Cons: Slower than Set for large datasets, as it involves searching through all properties. 3. **Map (get())**: * Pros: Fast and efficient lookup, especially for large maps. * Cons: Not suitable for small datasets, as the overhead of creating a Map can be significant. **Library/Feature Usage** In this benchmark, no libraries or features are used beyond the standard JavaScript data structures. However, it's worth noting that the `Map` data structure was introduced in ECMAScript 2015 (ES6) and has since become widely supported. **Special JS Features/Syntax** This benchmark does not use any special JavaScript features or syntax beyond what is required to test the performance of Sets, Objects, and Maps.
Related benchmarks:
Object access by key vs Map.get
Array from() vs Map.keys()
Array from() vs Map.keys() vs Map.values() vs spread
Map.set vs Object assign
Object.fromEntries vs Map
Comments
Confirm delete:
Do you really want to delete benchmark?