Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. array.includes - 1000 UUIDs
(version: 0)
Comparing performance of:
includes vs lookup
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = Array(1000).fill().map(() => crypto.randomUUID());; var b = new Set(a)
Tests:
includes
return a.includes(9)
lookup
return b.has(9)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
includes
lookup
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. **What is being tested?** The test measures the performance difference between two approaches to check if an element exists in an array: 1. Using the `includes` method on the array itself (e.g., `a.includes(9)`). 2. Using the `has` method on a Set data structure created from the same array elements (e.g., `b.has(9)`). **Options compared** The two approaches being compared are: * `Array.includes`: This method checks if an element exists in the array by iterating over each element and comparing it to the target value. If no match is found, it returns `false`. * Set `has`: This method uses a hash table (an internal data structure of sets) to quickly check if an element exists. **Pros and Cons** 1. **Array.includes**: * Pros: Widely supported, easy to use, and well-documented. * Cons: Iterates over the entire array for each element check, making it less efficient than Set `has` for large arrays. 2. **Set has**: * Pros: Faster lookup times, especially for large datasets since it uses a hash table internally. * Cons: Less widely supported and may require more code to implement. **Library/Technology used** In this benchmark, the `crypto` library is used to generate 1000 random UUIDs (`crypto.randomUUID()`). The Set data structure is also part of the JavaScript standard library ( ECMAScript). **Special JS feature/syntax** None are explicitly mentioned in the provided code or explanation. **Other alternatives** For checking if an element exists in an array, other approaches could be: * Using a `Map` instead of a Set * Implementing a custom iterative algorithm using bitwise operations However, these alternatives would likely have similar performance characteristics to Set `has`, and might not provide significant benefits over the standard approach. In summary, the benchmark measures the performance difference between using the widely supported `Array.includes` method versus the optimized `Set.has` method for checking if an element exists in a large array.
Related benchmarks:
Math.random vs crypto.getRandomValues vs uuid
Map vs Object UUID Key/Value
Set string vs number
Set string vs number #1
Comments
Confirm delete:
Do you really want to delete benchmark?