Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. array.includes large 2
(version: 0)
Comparing performance of:
includes vs lookup
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = []; for(let i = 0; i < 1000; i++){ a.push(i); } var b = new Set(a)
Tests:
includes
return a.includes(500)
lookup
return b.has(500)
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 and its test cases. **Benchmark Description** The benchmark compares two approaches: `set.has` (also known as "lookup" in the benchmark) and `array.includes`. These two methods are used to check if an element exists within a set or an array, respectively. **What is tested?** In this specific benchmark: * A large array (`a`) of 1000 elements is created using a loop. * A new Set object (`b`) is created from the array `a`. * Two test cases are executed: * One checks if an element (500) exists in the set (`set.has(500)`). * The other checks if an element (500) exists in the array (`array.includes(500)`). **Comparison of Options** The benchmark compares two options: * **`set.has`** (also known as "lookup"): This method is used to check if a value exists within a Set object. In JavaScript, a Set is an unordered collection of unique values. * Pros: * Efficient lookup: Sets provide fast lookups, with an average time complexity of O(1) for membership testing. * Unique values: Sets ensure that each element is unique, which can be beneficial when working with datasets that contain duplicates or need to eliminate redundant data. * Cons: * Limited use cases: Sets are suitable only for unique values and are not as flexible as arrays for certain operations (e.g., sorting, indexing). * **`array.includes`**: This method is used to check if a value exists within an array. In JavaScript, arrays are ordered collections of elements that can have duplicate values. * Pros: * Wide applicability: Arrays can be used for various operations like sorting, indexing, and manipulating data in a sequence-based manner. * Flexibility: Arrays support various methods like `indexOf()`, `filter()`, `map()`, etc., making them more versatile than sets for specific use cases. * Cons: * Inefficient lookup: Arrays provide slower lookups compared to sets, with an average time complexity of O(n) in JavaScript. **Library/Functionality Used** The benchmark uses two built-in JavaScript libraries: * **Set**: The Set object is used to create a unique collection of elements. This library provides fast membership testing and ensures that each element is unique. * **Array**: The Array prototype methods like `includes()` are utilized for checking if an element exists within the array. **Special JS Features/Syntax** There are no specific JavaScript features or syntax used in this benchmark, other than built-in libraries and functions like Set and Array.
Related benchmarks:
set.has vs. array.includes large 1
set.has vs. array.includes large 3
set.has vs. array.includes (1 million entries)
set vs array iteration 100k elements
Comments
Confirm delete:
Do you really want to delete benchmark?