Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
include vs set
(version: 0)
include vs set
Comparing performance of:
include vs set
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = ['a', 'b', 'c', 'k', 'm', 's', 'x']; var s = new Set(a); var tests = [...'abcdefghijklmnopqrstuvwxyz'];
Tests:
include
for(const t of tests) { a.includes(t); }
set
for(const t of tests) { s.has(t); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
include
set
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:134.0) Gecko/20100101 Firefox/134.0
Browser/OS:
Firefox 134 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
include
1593212.2 Ops/sec
set
7732457.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of MeasureThat.net and explore what's being tested in this benchmark. **What is being tested?** The provided JSON represents two test cases, each designed to measure the performance difference between using the `includes()` method versus creating a new `Set` object with an array as its argument. The test data consists of a predefined array `a` containing 7 elements and a larger string array `'abcdefghijklmnopqrstuvwxyz'`. **Options being compared** There are two main approaches being tested: 1. **Using `includes()`**: This approach uses the `includes()` method to check if each element in the `tests` array is present in the `a` array. 2. **Creating a new `Set` object with an array as its argument**: In this approach, a new `Set` object is created from the `a` array using the spread operator (`[...a]`). Then, each element in the `tests` array is checked against this set using the `has()` method. **Pros and Cons of each approach** 1. **Using `includes()`**: * Pros: Easy to implement, straightforward algorithm. * Cons: May be slower due to the overhead of string concatenation and searching for each element in the array. 2. **Creating a new `Set` object with an array as its argument**: * Pros: Can potentially be faster since looking up elements in a set is typically O(1) amortized time complexity compared to O(n) for linear searches. * Cons: Requires creating a new object, which may incur additional memory allocation and garbage collection overhead. **Library and purpose** The `Set` object used in the benchmark is part of the JavaScript API. A `Set` represents an unordered collection of unique values, allowing efficient membership testing using the `has()` method. **Special JS feature or syntax** None are explicitly mentioned in this benchmark. **Other alternatives** There are alternative approaches that could be considered: * Using a `Map` object instead of a `Set`: While both provide efficient membership testing, `Map`s offer additional functionality like key-value pairs. * Utilizing a data structure optimized for fast lookup, such as a trie or a hash table: These data structures might outperform the built-in `Set` and `includes()` methods in specific scenarios. Keep in mind that these alternatives may not be relevant to this particular benchmark's focus on comparing the performance of `includes()` versus creating a new `Set` object.
Related benchmarks:
set vs array
set.has vs. array.includes string values
set.has vs. array.includes (string input)
set.has vs. array.includes 2333
Array.include vs Set.has
Comments
Confirm delete:
Do you really want to delete benchmark?