Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. array.includes (with big array and last index match)
(version: 0)
Comparing performance of:
includes vs lookup
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 9]; 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 definition and test cases to understand what is being tested. **Benchmark Definition:** The benchmark definition consists of two separate tests: 1. `set.has vs. array.includes (with big array and last index match)`: This test compares the performance of two approaches: * Using `Set` data structure (`b`) to check if an element exists (`b.has(9)`). * Using `array.includes()` method to check if a specific value is present in an array (`a.includes(9)`). **Individual Test Cases:** There are two individual test cases: 1. `includes`: This test case measures the performance of using `array.includes()` method with a large array and searching for a specific element (in this case, 9). 2. `lookup`: This test case measures the performance of using `Set` data structure (`b`) to check if an element exists (`b.has(9)`). **What is being tested?** The benchmark is testing the performance of two different approaches: * Using a modern JavaScript data structure (`Set`) to perform fast lookups. * Using a built-in array method (`includes()`) to search for elements in an array. **Options Compared:** Two options are compared: 1. `array.includes()` method 2. `Set` data structure (`b.has()` method) **Pros and Cons of Each Approach:** 1. **Array Includes Method (`array.includes()`):** * Pros: + Widely supported and well-maintained. + Fast for small to medium-sized arrays. * Cons: + Has a higher overhead due to the way it searches through the array. + Can be slow for very large arrays or when searching for elements near the beginning of the array. 2. **Set Data Structure (`b.has()`):** * Pros: + Fast and efficient for fast lookups. + Can handle large datasets efficiently. * Cons: + Limited support and less maintained compared to `array.includes()`. + May have higher overhead due to the creation of a new data structure. **Library Used:** The benchmark uses the `Set` library, which is a built-in JavaScript feature. It provides an efficient way to store unique values and check for existence. **Special JS Feature/Syntax:** There are no special JavaScript features or syntax used in this benchmark. The focus is on testing the performance of two different approaches using standard JavaScript data structures and methods. In summary, this benchmark tests the performance of two different approaches: * Using a built-in array method (`array.includes()`) for searching elements in an array. * Using a modern JavaScript data structure (`Set`) to perform fast lookups.
Related benchmarks:
unique elements in array using filter - large array
set.has vs. array.includes bigger sample
set.has vs. array.includes (with big array)
set.has vs. array.includes (300 elements)
Comments
Confirm delete:
Do you really want to delete benchmark?