const target = 100;
if (target === 1 ||
target === 2 ||
target === 3 ||
target === 4 ||
target === 5 ||
target === 6 ||
target === 7 ||
target === 8 ||
target === 9 ||
target === 10 ||
target === 11 ||
target === 12 ||
target === 13 ||
target === 14 ||
target === 15 ||
target === 16 ||
target === 17 ||
target === 18 ||
target === 19 ||
target === 20 ||
target === 21 ||
target === 22 ||
target === 23 ||
target === 24 ||
target === 25 ||
target === 26 ||
target === 27 ||
target === 28 ||
target === 29 ||
target === 30 ||
target === 31 ||
target === 32 ||
target === 33 ||
target === 34 ||
target === 35 ||
target === 36 ||
target === 37 ||
target === 38 ||
target === 39 ||
target === 40 ||
target === 41 ||
target === 42 ||
target === 43 ||
target === 44 ||
target === 45 ||
target === 46 ||
target === 47 ||
target === 48 ||
target === 49 ||
target === 50 ||
target === 51 ||
target === 52 ||
target === 53 ||
target === 54 ||
target === 55 ||
target === 56 ||
target === 57 ||
target === 58 ||
target === 59 ||
target === 60 ||
target === 61 ||
target === 62 ||
target === 63 ||
target === 64 ||
target === 65 ||
target === 66 ||
target === 67 ||
target === 68 ||
target === 69 ||
target === 70 ||
target === 71 ||
target === 72 ||
target === 73 ||
target === 74 ||
target === 75 ||
target === 76 ||
target === 77 ||
target === 78 ||
target === 79 ||
target === 80 ||
target === 81 ||
target === 82 ||
target === 83 ||
target === 84 ||
target === 85 ||
target === 86 ||
target === 87 ||
target === 88 ||
target === 89 ||
target === 90 ||
target === 91 ||
target === 92 ||
target === 93 ||
target === 94 ||
target === 95 ||
target === 96 ||
target === 97 ||
target === 98 ||
target === 99 ||
target === 100) {
console.log('Found');
}
const target = 100;
if ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100].includes(target)) {
console.log('Found');
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Simple condition operator | |
includes function |
Test name | Executions per second |
---|---|
Simple condition operator | 82761.6 Ops/sec |
includes function | 90971.9 Ops/sec |
Let's break down the provided benchmark and explain what's being tested.
Benchmark Definition
The benchmark is defined as follows:
Name
: The name of the benchmark, which is "includes() vs multiple && / ||".Description
: An empty description.Script Preparation Code
and Html Preparation Code
: These are left blank, indicating that no specific code needs to be prepared for the benchmark.Individual Test Cases
There are two test cases:
includes()
method, which checks if an array contains a specific value.What's being tested
The benchmark tests the performance difference between using a simple condition operator (with multiple AND and OR operations) versus the includes()
method when checking if a value is within an array.
Options compared
Two options are compared:
includes()
method to check if the number is in the array.Pros and Cons of each approach
Here's a brief summary:
Latest Benchmark Result
The latest benchmark result shows that:
includes()
method is slightly faster than the simple condition operator.Based on this information, it's clear that using the includes()
method can be a more efficient approach when checking if a value is within an array. However, it's worth noting that the actual performance difference may depend on various factors, such as the size of the array and the specific use case.