Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set vs Object vs Map, Access
(version: 0)
Compare the speed to retrieve a value from three data structures that can be used for boolean referencing; i.e. for mapping enabled settings.
Comparing performance of:
Set vs Object vs Map
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var set = new Set(["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]); var object = {"one": true, "two": true, "three": true, "four": true, "five": true, "six": true, "seven": true, "eight": true, "nine": true, "ten": true}; var map = new Map([["one", true], ["two", true], ["three", true], ["four", true], ["five", true], ["six", true], ["seven", true], ["eight", true], ["nine", true], ["ten", true]]); var values = Object.keys(object);
Tests:
Set
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
object['one']; object['two']; object['three']; object['four']; object['five']; object['six']; object['seven']; object['eight']; object['nine']; object['ten'];
Map
map.get('one'); map.get('two'); map.get('three'); map.get('four'); map.get('five'); map.get('six'); map.get('seven'); map.get('eight'); map.get('nine'); map.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:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0
Browser/OS:
Firefox 146 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Set
16079801.0 Ops/sec
Object
772714432.0 Ops/sec
Map
16243066.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON benchmark and its test cases to understand what is being tested, the options compared, pros, cons, and other considerations. **Benchmark Definition:** The benchmark compares the speed of retrieving values from three data structures that can be used for boolean referencing: 1. **Set**: A collection of unique values, which can be used to store boolean settings. 2. **Object**: An object with string keys, where each key has a corresponding boolean value. 3. **Map**: An unordered collection of key-value pairs, where each key is unique and maps to a specific value. **Test Cases:** Each test case consists of a benchmark definition that performs the same operation multiple times. The operations are: * `set.has('one');` (Set) * `object['one'];` (Object) * `map.get('one');` (Map) The number of executions for each operation is not specified, but it can be inferred from the "ExecutionsPerSecond" value in the benchmark results. **Options Compared:** The three data structures are compared in terms of their performance when used to retrieve boolean values. The test aims to determine which data structure is fastest for this specific use case. **Pros and Cons:** 1. **Set**: * Pros: Fast lookups (O(1) on average), efficient memory usage, and simple implementation. * Cons: Not designed for storing boolean values; may not be suitable for other types of data. 2. **Object**: * Pros: Widely supported and well-established, easy to implement, and flexible. * Cons: Slow lookups (O(n) in the worst case), and may lead to slower performance due to object lookup overhead. 3. **Map**: * Pros: Fast lookups (O(1) on average), efficient memory usage, and flexible key-value pairs. * Cons: May not be as widely supported as objects; requires careful key management. **Other Considerations:** * Memory usage: All three data structures have relatively low memory overhead for storing a small set of boolean values. * Implementation complexity: Sets and maps are generally easier to implement than objects, especially when it comes to handling null or undefined keys. * Browser support: The test results indicate that Chrome 129 is used as the testing browser. It's essential to consider other browsers and versions when comparing performance across different data structures. **Alternative Approaches:** If not using sets, objects, or maps, alternative approaches could include: 1. **Array**: Using a boolean array to store settings can be efficient, but may require more memory than the other options. 2. **Boolean flag**: Implementing a simple boolean flag system using a single variable can be very lightweight but might lead to slower performance due to branching and overhead. 3. **Custom data structure**: Depending on specific requirements, it's possible that a custom data structure could be designed to optimize for boolean referencing, potentially offering better performance than the existing options. Keep in mind that this analysis is based on general knowledge of JavaScript data structures and their performance characteristics. The actual results may vary depending on the specific implementation, usage patterns, and browser versions.
Related benchmarks:
Create Object vs Map vs Array vs Set
Set vs Object vs Map (has/in)
Set vs Object vs Map (has/in) vs array
Set vs Object vs Map, Access (mutable, growing)
Comments
Confirm delete:
Do you really want to delete benchmark?