Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set array expansion
(version: 0)
Tests the implications of expanding large sets into an array for finding values within them
Comparing performance of:
[...] vs Set.prototype.values()
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var mySet = new Set(); // Generate and add 10,000 unique items to the set for (let i = 0; i < 10000; i++) { mySet.add(i); }
Tests:
[...]
[...mySet]
Set.prototype.values()
mySet.values()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
[...]
Set.prototype.values()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser/OS:
Chrome 124 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
[...]
75898.0 Ops/sec
Set.prototype.values()
27722386.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON for the "Set array expansion" benchmark. **What is being tested?** The benchmark tests two different approaches to working with large sets in JavaScript: 1. **Expanding the set into an array using the spread operator (`[...mySet]`)**: This approach converts the `Set` object into an array, allowing for indexing and iteration. 2. **Using the `values()` method of the `Set` prototype**: This approach returns a live view of the set's values as an iterable sequence. **Options being compared** The benchmark compares the performance of these two approaches: * Expanding the set into an array using `[...mySet]` * Using the `values()` method of the `Set` prototype **Pros and Cons of each approach:** 1. **Expanding the set into an array using `[...mySet]`**: * Pros: + Allows for indexing and iteration, which can be beneficial in certain scenarios. + Can be used with existing array methods and libraries. * Cons: + Creates a new array, which can lead to increased memory usage and slower performance. + May not be the most efficient way to access individual elements or iterate over the set's values. 2. **Using the `values()` method of the `Set` prototype**: * Pros: + Returns an iterable sequence, which allows for lazy iteration and reduced memory usage. + Can be more efficient than expanding the set into an array. * Cons: + May not support indexing or iteration in the same way as an array. + Requires specific knowledge of the `Set` prototype's methods. **Library used** The benchmark uses the built-in `Set` object and its `values()` method, which is a part of the JavaScript standard library. No external libraries are required. **Special JS feature or syntax** This benchmark does not use any special JavaScript features or syntax beyond what's already covered by the standard library (e.g., `let`, `const`, `for`, etc.). **Other alternatives** If you're interested in exploring other approaches, here are a few examples: * Using a different data structure, such as an array or object, to represent the set. * Implementing your own iteration mechanism for sets using loops and conditional statements (as opposed to relying on built-in methods like `values()`). * Using external libraries or frameworks that provide optimized implementations of set operations. Keep in mind that these alternatives might not be supported by all JavaScript engines or environments.
Related benchmarks:
loop over Set conditionally vs non-conditionally
Array.from vs. ... expansion
set vs array iteration 100k elements
set vs array iteration new new
3set vs array iteration New doge333
Comments
Confirm delete:
Do you really want to delete benchmark?