!['PDP Why Not Try', 'PDP Recently Viewed'].includes('PDP Why Not Try')
!['PDP Why Not Try', 'PDP Recently Viewed'].includes('PDP Recently Viewed')
!['PDP Why Not Try', 'PDP Recently Viewed'].includes('blarg')
!['PDP Why Not Try', 'PDP Recently Viewed'].find(origin => origin === 'PDP Why Not Try')
['PDP Why Not Try', 'PDP Recently Viewed'].find(origin => origin === 'PDP Recently Viewed')
['PDP Why Not Try', 'PDP Recently Viewed'].find(origin => origin === 'blarg')
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
includes: first | |
includes: second | |
includes: missing | |
find: first | |
find: second | |
find: missing |
Test name | Executions per second |
---|---|
includes: first | 1183822464.0 Ops/sec |
includes: second | 1187827712.0 Ops/sec |
includes: missing | 1187441664.0 Ops/sec |
find: first | 171276304.0 Ops/sec |
find: second | 168369808.0 Ops/sec |
find: missing | 168706304.0 Ops/sec |
I'll break down the provided benchmark definition and test cases to explain what's being tested, compared, and their pros/cons.
Benchmark Definition
The benchmark is defined as an empty object with no script preparation code, html preparation code, or description. This suggests that the benchmark relies on external libraries or built-in JavaScript functionality to perform its tests.
Test Cases
There are six test cases, each comparing a different scenario:
includes: first
- Verifies if "!['PDP Why Not Try', 'PDP Recently Viewed'].includes('PDP Why Not Try')` returns true.includes: second
- Verifies if "!['PDP Why Not Try', 'PDP Recently Viewed'].includes('PDP Recently Viewed')` returns true.includes: missing
- Verifies if "!['PDP Why Not Try', 'PDP Recently Viewed'].includes('blarg')` returns false (i.e., not found).find: first
- Verifies if "!['PDP Why Not Try', 'PDP Recently Viewed'].find(origin => origin === 'PDP Why Not Try')` returns the expected value.find: second
- Verifies if "!['PDP Why Not Try', 'PDP Recently Viewed'].find(origin => origin === 'PDP Recently Viewed')` returns the expected value.find: missing
- Verifies if "!['PDP Why Not Try', 'PDP Recently Viewed'].find(origin => origin === 'blarg')` returns undefined (i.e., not found).Libraries and Built-in Functionality
The benchmark relies on external libraries or built-in JavaScript functionality, specifically:
includes()
: A method that checks if a value exists in an array.find()
: A method that searches for the first element in an array that satisfies a provided condition.These methods are part of the ECMAScript standard and are implemented by most modern JavaScript engines, including Chrome.
Special JS Features or Syntax
There is no special JavaScript feature or syntax being used in this benchmark. However, the use of arrow functions (origin => origin === 'PDP Why Not Try'
) is a relatively recent feature introduced in ECMAScript 2015 (ES6).
Pros and Cons of Different Approaches
For includes()
:
For find()
:
includes()
.Other Considerations
The benchmark seems to focus on the performance differences between includes()
and find()
, with varying input scenarios. This suggests that the goal of the benchmark is to evaluate the performance characteristics of these methods under different conditions.
For a more comprehensive understanding of JavaScript performance, it's essential to consider other factors beyond just the includes()
and find()
methods, such as:
Alternatives
If you were to rewrite this benchmark with alternative approaches, some options could include:
indexOf()
instead of includes()
, which can be slower but still returns a non-negative index value.Keep in mind that the optimal approach will depend on the specific use case and requirements of your project.