Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set vs Map vs Object for lookups
(version: 0)
Comparing performance of:
Object lookup vs Map lookup vs Set lookup vs Array lookup
Created:
4 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var list = ["Lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipisicing", "elit.", "Ullam", "nesciunt", "debitis,", "facilis", "qui", "possimus", "minus", "rerum", "velit", "saepe", "magnam,", "voluptatum", "quos", "eveniet", "ducimus", "facere", "harum", "itaque", "atque", "assumenda", "reiciendis", "exercitationem"] var set = new Set(["Lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipisicing", "elit.", "Ullam", "nesciunt", "debitis,", "facilis", "qui", "possimus", "minus", "rerum", "velit", "saepe", "magnam,", "voluptatum", "quos", "eveniet", "ducimus", "facere", "harum", "itaque", "atque", "assumenda", "reiciendis", "exercitationem"]) var map = new Map([ ["Lorem", true], ["ipsum", true], ["dolor", true], ["sit", true], ["amet", true], ["consectetur", true], ["adipisicing", true], ["elit.", true], ["Ullam", true], ["nesciunt", true], ["debitis,", true], ["facilis", true], ["qui", true], ["possimus", true], ["minus", true], ["rerum", true], ["velit", true], ["saepe", true], ["magnam,", true], ["voluptatum", true], ["quos", true], ["eveniet", true], ["ducimus", true], ["facere", true], ["harum", true], ["itaque", true], ["atque", true], ["assumenda", true], ["reiciendis", true], ["exercitationem", true], ]) var object = { "Lorem": true, "ipsum": true, "dolor": true, "sit": true, "amet": true, "consectetur": true, "adipisicing": true, "elit.": true, "Ullam": true, "nesciunt": true, "debitis,": true, "facilis": true, "qui": true, "possimus": true, "minus": true, "rerum": true, "velit": true, "saepe": true, "magnam,": true, "voluptatum": true, "quos": true, "eveniet": true, "ducimus": true, "facere": true, "harum": true, "itaque": true, "atque": true, "assumenda": true, "reiciendis": true, "exercitationem": true, }
Tests:
Object lookup
var b = object["consectetur"]
Map lookup
var b = map.has("consectetur")
Set lookup
var b = set.has("consectetur")
Array lookup
var b = list.find(e => e == "consectetur")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Object lookup
Map lookup
Set lookup
Array lookup
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Android 12; Mobile; rv:147.0) Gecko/147.0 Firefox/147.0
Browser/OS:
Firefox Mobile 147 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object lookup
1068884288.0 Ops/sec
Map lookup
1011549952.0 Ops/sec
Set lookup
1174597632.0 Ops/sec
Array lookup
69965904.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its various components. **Benchmark Definition** The benchmark is designed to compare the performance of three data structures: Sets, Maps, and Objects (with arrays as an additional reference point). The test aims to measure which data structure provides the fastest lookup time for a specific key. **Options Compared** The options being compared are: * Set (`new Set()`): A set is a collection of unique values that can be used to store and look up elements. * Map (`new Map()`): A map (or object in JavaScript) is an association of keys with values, where each value can be accessed using its corresponding key. * Object (`{key: value}`): An object in JavaScript is similar to a map but allows for nested objects and arrays as values. **Pros and Cons** Here's a brief summary of the pros and cons of each data structure: * Set: + Pros: Fast lookup, insertion, and deletion operations. + Cons: May not be suitable for storing complex data structures or large amounts of data. * Map: + Pros: Flexible data structure that can handle nested objects and arrays, fast lookup operations. + Cons: May have higher overhead compared to Sets due to the use of hash tables. * Object: + Pros: Allows for easy manipulation of nested objects and arrays, flexible data structure. + Cons: May not be as performant as Sets or Maps for simple key-value pairs. **Library and Purpose** In this benchmark, the `Map` and `Set` constructors are used to create instances of these data structures. The `Object` constructor is used to create an object with a specific key-value pair. The `find()` method in the array lookup test case is not directly related to any library, but rather a built-in JavaScript method that searches for a specified element within an array. **Individual Test Cases** Each test case measures the performance of a different data structure: * "Object lookup" tests the performance of accessing an object property using bracket notation (`object['consectetur']`). * "Map lookup" tests the performance of checking if a key exists in a map using the `has()` method. * "Set lookup" tests the performance of checking if a key exists in a set using the `has()` method. * "Array lookup" tests the performance of finding an element within an array using the `find()` method. **Latest Benchmark Results** The latest benchmark results show the execution times per second for each test case on a Chrome Mobile iOS device. The results indicate that: * Map lookup is the fastest, with an average of 34,003,464 executions per second. * Set lookup is slightly slower than Map lookup, with an average of 30,403,464 executions per second. * Object lookup is the slowest, with an average of 25,673,204 executions per second. * Array lookup is the fastest among all options, with an average of 25,667,204 executions per second.
Related benchmarks:
Create Object vs Map vs Array vs Set
Set vs Object vs Map has value
Set vs Object vs Map Retrieval
Value exists in Set vs Object vs Map
Comments
Confirm delete:
Do you really want to delete benchmark?