Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set vs Map cs
(version: 0)
Comparing performance of:
Set 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"]); for(let i = 0; i < 1000; i++) set.add("xx"+ i);
Map
var map = new Map([["one", true], ["two", true], ["three", true], ["four", true], ["five", true], ["six", true], ["seven", true], ["eight", true], ["nine", true], ["ten", true]]); for(let i = 0; i < 1000; i++) map.set("xx"+ i, true);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Set
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):
Let's break down the provided benchmark and explain what's being tested, compared, and their pros/cons. **What is being tested?** The benchmark is testing two approaches for storing and iterating over a large dataset: `Set` and `Map`. A `Set` in JavaScript is an unordered collection of unique values, while a `Map` is an unordered collection of key-value pairs. Both data structures are implemented as hash tables under the hood. **Options compared** The benchmark is comparing two approaches: 1. **Set**: Using a `Set` to store and iterate over the dataset. 2. **Map**: Using a `Map` to store and iterate over the dataset. **Pros/Cons of each approach:** * **Set:** + Pros: - Fast iteration and lookup times, as elements are stored in an unordered but hash-table-based data structure. - No duplicate values, which can be beneficial for certain use cases. + Cons: - Does not preserve the original order of elements. - Not suitable for storing key-value pairs or requiring explicit key access. * **Map:** + Pros: - Preserves the original order of elements (thanks to the `insert()` method). - Allows for explicit key access, which can be beneficial in certain scenarios. + Cons: - Slower iteration and lookup times compared to `Set`, as elements are stored in an unordered but hash-table-based data structure. **Library usage** Neither of the benchmarked approaches uses any external libraries. The `Set` and `Map` APIs are built-in JavaScript constructs, implemented by the browser's engine (in this case, Chrome). **Special JS feature or syntax** None mentioned. Both test cases use standard JavaScript syntax. **Other considerations:** * The dataset size is 10 elements, repeated 1000 times. This may not be representative of large-scale datasets. * The benchmark measures `ExecutionsPerSecond`, which indicates the number of iterations performed per second. A higher value typically indicates better performance. **Alternatives:** If you were to implement this benchmark yourself, you could also consider using: 1. **Array**: Using an array as a data structure and iterating over it. 2. **WeakMap**: Using a `WeakMap` to store key-value pairs. 3. **Set-like data structures**: Implementing your own custom set or map data structure from scratch. Keep in mind that these alternatives may have varying performance characteristics compared to the built-in `Set` and `Map` APIs used in this benchmark.
Related benchmarks:
Create Map/Set vs reuse Map/Set
Array from() vs Map.keys()
Array from() vs Map.keys() vs Map.values() vs spread
Array from() vs Map.keys() vs Map.values() vs spread (fixed)
Map sets vs gets
Comments
Confirm delete:
Do you really want to delete benchmark?