Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set has vs list includes
(version: 0)
Comparing performance of:
get from set nope vs get from set last vs get from set first vs get from list nope vs get from list last vs get from list first
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
get from set nope
new Set([470,364,173,535,140,374,442,64,245,69,323,155,529,405,131,431,445,281,164,576]).has(51)
get from set last
new Set([470,364,173,535,140,374,442,64,245,69,323,155,529,405,131,431,445,281,164,576]).has(576)
get from set first
new Set([470,364,173,535,140,374,442,64,245,69,323,155,529,405,131,431,445,281,164,576]).has(470)
get from list nope
[470,364,173,535,140,374,442,64,245,69,323,155,529,405,131,431,445,281,164,576].includes(51)
get from list last
[470,364,173,535,140,374,442,64,245,69,323,155,529,405,131,431,445,281,164,576].includes(576)
get from list first
[470,364,173,535,140,374,442,64,245,69,323,155,529,405,131,431,445,281,164,576].includes(470)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
get from set nope
get from set last
get from set first
get from list nope
get from list last
get from list first
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 test cases. **Benchmark Definition JSON** The benchmark definition represents a JavaScript code snippet that creates a Set or an array and tests whether a specific value is present in it using either `has()` (for Sets) or `includes()` (for arrays). **Options Compared** 1. **Set has() vs List includes()**: The two main options being compared are: * Using the `has()` method on a Set to check if a value is present. * Using the `includes()` method on an array to check if a value is present. 2. **Get from Set (first/last/nope) vs Get from List (first/last/nope)**: Within each of the two options above, there are three variations: * Getting the first element in the set/array using indexing (`[index]`) or `values()` method. * Getting the last element in the set/array using indexing (`[index]`) or `values()` method and then slicing from the end (`slice()`) or indexing from the end (`[index - 1]`). * Not finding a specific value in the set/array (i.e., no match). **Pros and Cons** **Set has() vs List includes():** * **Pros:** + `has()` is generally faster than `includes()` because it uses a hash table for lookup, which provides constant-time complexity. + Less memory allocation overhead when using Sets compared to arrays. * **Cons:** + Not all browsers support the `has()` method (e.g., older versions of Chrome). + May not work correctly with non-numeric values. **Get from Set vs Get from List:** * **Pros:** + Using Sets provides better memory efficiency and faster lookups. + Can be more concise than using arrays for large datasets. * **Cons:** + May require additional logic to handle edge cases (e.g., getting the first/last element). + Not suitable for all use cases, such as when working with non-numeric values or requiring a specific order. **Other Considerations** * The `has()` method is generally faster than `includes()` because it uses a hash table for lookup. * Using Sets can provide better memory efficiency and faster lookups compared to arrays. * Not all browsers support the `has()` method, so tests should be run on multiple platforms to ensure compatibility. **Library/Functionality Used** None of the test cases use external libraries or functions other than built-in JavaScript methods (`Set`, `Array`, `includes`, `has`). **Special JS Features/Syntax** There are no special JS features or syntax used in these benchmark tests, as they only utilize standard built-in methods and data structures. **Alternatives** Other alternatives to these benchmarks could include: * Comparing the performance of other set-based data structures (e.g., Maps) vs array-based data structures. * Testing different indexing techniques for arrays (e.g., `map()`, `forEach()`). * Evaluating the performance of various sorting algorithms (e.g., QuickSort, MergeSort). Keep in mind that these alternatives would require significant modifications to the benchmark test cases and may not be directly comparable.
Related benchmarks:
convert to set + set.has vs. array.includes
new Set([x]).has vs [x].includes
array.includes vs. set.has on the fly
Array includes vs Set.has
set.has (w/ creation) vs. array.includes
Comments
Confirm delete:
Do you really want to delete benchmark?