Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.includes vs Set.has vas Json retrive
(version: 0)
Comparing performance of:
Array includes vs Set has vs json retrive data
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; var b = new Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); var c = { "1":1, "2":1, "3":1, "4":1, "5":1, "6":1, "7":1, "8":1, "9":1, "10":1 }
Tests:
Array includes
return a.includes(9);
Set has
return b.has(9);
json retrive data
return c[9];
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Array includes
Set has
json retrive data
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Array includes
36098860.0 Ops/sec
Set has
35943432.0 Ops/sec
json retrive data
35826320.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in the provided JSON benchmark. **Benchmark Definition** The benchmark measures the performance of three different approaches to check if a value exists in an array or object: 1. **Array.includes**: Checks if a specific value exists in an array using the `includes()` method. 2. **Set.has**: Uses a Set data structure to store unique values and checks if a specific value exists in the set using the `has()` method. 3. **JSON retrieval**: Retrieves a value from a JSON object using bracket notation (`c[9]`). **Options Compared** The benchmark compares the performance of these three approaches: * **Array.includes**: This approach uses the built-in `includes()` method, which is supported by modern JavaScript engines. * **Set.has**: This approach uses a Set data structure to store unique values. Sets are optimized for fast lookups and are often used when working with unique identifiers or hashable values. * **JSON retrieval**: This approach uses bracket notation to directly access a value in the JSON object. This is not as efficient as using an array or set, but it's still a valid option. **Pros and Cons** Here's a brief summary of the pros and cons of each approach: * **Array.includes**: + Pros: Widely supported by modern browsers, easy to use. + Cons: Can be slower than Set.has for large datasets, may incur additional overhead due to method calls. * **Set.has**: + Pros: Fast lookups, optimized for unique values. + Cons: Requires creating a set object, which can incur additional overhead. * **JSON retrieval**: + Pros: Simple and straightforward. + Cons: Can be slower than other approaches, may not work well with large datasets. **Library and Purpose** None of the libraries mentioned in the benchmark definition are explicitly required. However, if you were to implement a custom set data structure, you might use a library like `js-set` or `fast-set`. **Special JS Feature/Syntax** There is no special JavaScript feature or syntax being tested in this benchmark. The approaches compared are all standard, widely supported methods. **Alternatives** Other alternatives for checking if a value exists in an array or object include: * Using the `indexOf()` method instead of `includes()`. * Using the `in` operator to check if a property exists in an object. * Using a library like Lodash or Underscore.js, which provide optimized implementations of these methods. Keep in mind that the performance differences between these approaches may be negligible for small datasets. However, as the size of the dataset grows, one of these approaches will likely outperform the others.
Related benchmarks:
convert to set + set.has vs. array.includes
Includes (array) vs Has (Set)
array.includes vs. set.has on the fly
Array.includes vs Set.has vas Map.has 2
Array includes vs Set.has
Comments
Confirm delete:
Do you really want to delete benchmark?