Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
set.has vs. array.includes (random string values), add strings not in list, smaller list
(version: 0)
Comparing performance of:
arr.includes vs set.has
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = [ 'height', 'width', 'maxHeight', 'maxWidth', 'maxHeight', 'minWidth', 'color', 'bg', 'backgroundColor', 'opacity', 'm', 'mt', 'mb', 'mr' ]; var b = new Set(a) var c = a.slice(); c.push('abc','def','ghi','other word', 'notinlist','123','4334232313','borderwersese');
Tests:
arr.includes
return a.includes(c[Math.floor(Math.random() * c.length)])
set.has
return b.has(c[Math.floor(Math.random() * c.length)])
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
arr.includes
set.has
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 JSON data and explain what's being tested, compared, and other considerations. **Benchmark Definition** The benchmark is designed to compare two JavaScript methods: `array.includes()` and `Set.has()`. The test aims to measure which method is faster for adding a string that is not in the list. **Script Preparation Code** The script prepares two arrays: * `a`: an array of strings, including some duplicates. * `c`: a copy of `a` with additional random strings added to it, including one string that is not in the original array (`'notinlist'`). A new Set object `b` is created from the elements of array `a`. **Html Preparation Code** There is no HTML preparation code provided. **Individual Test Cases** The benchmark consists of two test cases: 1. `arr.includes`: This test case uses the `array.includes()` method to check if a random string from array `c` is present in array `a`. 2. `set.has`: This test case uses the `Set.has()` method to check if a random string from array `c` is present in Set object `b`. **Options Compared** The two methods are compared: * `array.includes()` * `Set.has()` **Pros and Cons of Each Approach** 1. **Array Includes()** * Pros: + Simple to implement. + Fast for small arrays. * Cons: + May not be optimized for larger arrays, leading to slower performance. + May perform a linear search through the array, which can be slow for large datasets. 2. **Set.Has()** * Pros: + Optimized for fast lookups in sets. + Uses a hash table under the hood, making it efficient for large datasets. * Cons: + May require additional memory overhead due to the set data structure. + May have slower performance for small arrays or when adding elements is expensive. **Other Considerations** * **Memory Usage**: The benchmark may impact memory usage, especially if the array and Set objects are very large. This could affect system performance or lead to memory-related issues. * **Cache Efficiency**: The benchmark's performance may be influenced by cache efficiency. For example, `Set.has()` might benefit from cache locality due to its hash table implementation. * **Browser and Platform Variations**: The benchmark results may vary across different browsers, platforms, or versions due to differences in JavaScript engine optimizations, caching, and other factors. **Library/Module Used** The benchmark uses the built-in `Array` and `Set` objects, which are part of the ECMAScript standard. These objects provide optimized implementations for array and set operations, respectively. **Special JS Feature/Syntax** There is no specific JavaScript feature or syntax used in this benchmark that requires special explanation. The focus is on comparing two existing methods: `array.includes()` and `Set.has()`.
Related benchmarks:
set.has vs. array.includes (random string values), add strings not in list
lodash uniq vs set strings
lodash uniq vs set with strings
indexof vs set123
Comments
Confirm delete:
Do you really want to delete benchmark?