array find vs new Set has inside a filter (version: 1)
I created two arrays: one with 100 numbers and another with 10,000 random numbers. Then, i filtered the first array to check for the presence of the number 5 in the second array using two different methods.
In the first test case, i used the .find() method, which iterates through the 10,000-number array to locate the number 5 and returns the first matching value.
In the second test case, i converted the 10,000-number array into a Set and used the .has() method to check for the presence of the number 5.
The goal is to compare both approaches and determine which one is faster and which one use less memory.
Comparing performance of: array find vs new Set has
Memory measurements supported only in Chrome.
For precise memory measurements Chrome must be launched with --enable-precise-memory-info flag.
More information: Monitoring JavaScript Memory
Test case name
Result
array find
new Set has
Fastest:N/A
Slowest:N/A
Latest run results:
Run details: (Test run date:
one month ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36