Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. array.includes of html input types
(version: 0)
Comparing performance of:
includes end vs lookup end vs includes beginning vs lookup beginning
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = ["button", "checkbox", "color", "date", "datetime-local", "email", "file", "hidden", "image", "month", "number", "password", "radio", "range", "reset", "search", "submit", "tel", "text", "time", "url", "week"]; var b = new Set(a)
Tests:
includes end
return a.includes("week")
lookup end
return b.has("week")
includes beginning
return a.includes("button")
lookup beginning
return b.has("button")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
includes end
lookup end
includes beginning
lookup beginning
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):
**Benchmark Overview** The provided benchmark measures the performance of two JavaScript methods: `array.includes()` and `Set.has()`, on HTML input types. **Method Comparison** Two methods are compared: 1. **`array.includes()`**: This method checks if an element is present in a given array. 2. **`Set.has()`**: This method checks if an element is present in a given Set data structure. **Pros and Cons of Each Method** ### `array.includes()` Pros: * Widely supported by most modern JavaScript engines * Fast lookup time, especially for large arrays Cons: * Can be slower for small arrays or specific use cases due to the overhead of searching the array * May not perform well on certain data types (e.g., objects) if a custom `includes` method is used ### `Set.has()` Pros: * Fast lookup time, especially for large sets * Suitable for use with unique values or fast membership testing * Can be faster than `array.includes()` in some cases due to the inherent properties of Sets (e.g., O(1) average time complexity) Cons: * Less widely supported by older JavaScript engines or environments that don't support Sets * May require additional setup or configuration for certain use cases **Library Usage** The benchmark uses a library called `Set`, which is built into modern JavaScript engines. The Set data structure is used to store an array of HTML input types, allowing for fast membership testing and lookup. **Special JS Feature/Syntax** No special features or syntax are used in this benchmark. However, it's worth noting that the use of Sets and the `includes()` method are part of modern JavaScript standard library features. **Other Alternatives** For those who might be interested in exploring alternative methods: 1. **`array.indexOf()`**: This method returns the index of the first occurrence of an element in a given array, or -1 if not found. 2. **`indexOf()`: `Set.has()` with custom implementation**: For those who don't have access to built-in Set support, a custom implementation using an object and the `in` operator can be used. Keep in mind that these alternatives may have different performance characteristics and use cases compared to the original methods being benchmarked.
Related benchmarks:
array.includes vs set.has for small n
set.has vs. array.includes v22
set vs array find if exists
array.includes vs. set.has on the fly
Array includes vs Set.has
Comments
Confirm delete:
Do you really want to delete benchmark?