Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set vs Array Privilege Check
(version: 0)
Comparing performance of:
Includes Performance vs Has Performance
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var i = Math.floor(Math.random() * 500) + 1; var a = [...Array(500).keys()]; var b = new Set(a);
Tests:
Includes Performance
return a.includes(i);
Has Performance
return b.has(i);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Includes Performance
Has Performance
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/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Includes Performance
93628608.0 Ops/sec
Has Performance
110882352.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Overview** The benchmark measures the performance of two different approaches to check if an element exists in a Set or Array: 1. `a.includes(i)` 2. `b.has(i)` Here, `a` is an Array created with 500 elements from `Array(500).keys()`, and `b` is a Set created from the same array. **Options Compared** The benchmark compares two options: A) Using the `includes()` method on an Array (`a.includes(i)`) B) Using the `has()` method on a Set (`b.has(i)`) **Pros and Cons of Each Approach** **A) Using includes() on an Array:** Pros: * Widely supported in most browsers * Easy to implement Cons: * Has a linear search algorithm, which can be slow for large arrays * May not be optimized by the browser's engine **B) Using has() on a Set:** Pros: * Has a constant-time lookup (O(1)) on average, making it faster than Array.includes() * Optimized by most browsers' engines Cons: * Not supported in older browsers or those with limited Set support * Requires creating a Set object **Library Usage** In this benchmark, the `Set` library is used to create a set from the array elements. Sets are data structures that store unique values and provide fast membership testing. The purpose of using a Set here is to demonstrate the performance difference between checking existence in an Array versus a Set. **Special JS Feature or Syntax** There isn't any special JavaScript feature or syntax mentioned in this benchmark. The focus is on comparing two basic operations: `includes()` on an Array and `has()` on a Set. **Other Alternatives** If you want to compare other approaches, here are some alternatives: * Using `indexOf()` on an Array (`a.indexOf(i)`) * Using `filter()` on an Array (not applicable in this case, since we're looking for existence) * Using regular expressions with the `test()` method Keep in mind that each alternative may have its own pros and cons, and some might not be supported or optimized by all browsers.
Related benchmarks:
set.has vs. array.includes (big)
set.has vs. array.includes - large array - random Access
map.has vs. array.includes - large array - random Access
unique set or object
Comments
Confirm delete:
Do you really want to delete benchmark?