Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Copying Set vs Object vs Map
(version: 0)
Comparing performance of:
Set vs Object vs Map
Created:
5 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 obj = {"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]]);
Tests:
Set
var set2 = new Set(set) set2.add('foo')
Object
var obj2 = { ...obj, 'foo': true }
Map
var map2 = new Map(map) map2.set('foo', 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:
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):
**What is being tested?** The provided JSON represents a JavaScript microbenchmark that compares the performance of three data structures: Sets, Objects, and Maps. Each test case measures the execution time of a specific operation on each data structure. **Options compared:** 1. **Sets**: A Set is an unordered collection of unique values. In this benchmark, the test case creates a new Set from a given array, adds a new element to it. 2. **Objects**: An Object is an unordered collection of key-value pairs. In this benchmark, the test case creates a new Object by spreading an existing object and adding a new property to it. 3. **Maps**: A Map is an unordered collection of key-value pairs. In this benchmark, the test case creates a new Map from a given array of key-value pairs and adds a new entry to it. **Pros and Cons:** * **Sets**: + Pros: Fast lookup, insertion, and deletion operations due to their hash table implementation. + Cons: May not be suitable for use cases that require preserving the order of elements. * **Objects**: + Pros: Easy to create and manipulate, with a familiar syntax for developers. + Cons: Slow lookup, insertion, and deletion operations compared to Sets or Maps due to their object-oriented implementation. * **Maps**: + Pros: Fast key lookup and insertion operations, similar to Sets. Additionally, preserves the order of elements. + Cons: May be less intuitive than Sets or Objects for developers unfamiliar with Maps. **Library usage:** None of the provided test cases uses any external libraries. **Special JS features or syntax:** There are no special JavaScript features or syntax used in these benchmark test cases. The code is written in standard JavaScript and relies on the built-in data structures (Sets, Objects, Maps) and operations. **Other alternatives:** If you wanted to compare the performance of other data structures, such as Arrays or Linked Lists, you could add additional test cases with similar modifications to the benchmark definition. Some possible alternatives could include: * **Arrays**: Similar to Sets but with indexing and slicing capabilities. * **Linked Lists**: Data structures where elements are linked together, often used for efficient insertion and deletion operations. Keep in mind that each data structure has its own strengths and weaknesses, and choosing the right one depends on the specific use case and requirements.
Related benchmarks:
Map vs Vanilla For vs For Of 1000
Object spread vs New map
Object spread vs New map with string keys
test for Vovan
allocating objects vs allocating maps
Comments
Confirm delete:
Do you really want to delete benchmark?