"Hi this is a test, would you look at that".startsWith("bonjour")
"Hi this is a test, would you look at that".includes("bonjour")
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
"Hi this is a test, would you look at that".startsWith("bonjour") | |
"Hi this is a test, would you look at that".includes("bonjour") |
Test name | Executions per second |
---|---|
"Hi this is a test, would you look at that".startsWith("bonjour") | 166843536.0 Ops/sec |
"Hi this is a test, would you look at that".includes("bonjour") | 226867136.0 Ops/sec |
Let's break down the provided benchmark and its options.
What is being tested?
The benchmark is testing two string comparison methods: startsWith
and includes
. The test cases are comparing the performance of these two methods when there is no match in the string.
Options compared
The two options being compared are:
startsWith
: This method checks if the string starts with a specified substring.includes
: This method checks if the string contains a specified substring.Pros and Cons
startsWith
:includes
:startsWith
when the search pattern is near the beginning of the string.Library usage
There doesn't seem to be any library used in this benchmark. The test cases are using built-in JavaScript methods (startsWith
and includes
) without any additional dependencies.
Special JS feature or syntax
None mentioned.
Benchmark preparation code
The script preparation code is empty, which means that the benchmarking framework will likely generate a random string for testing.
Other alternatives
If this benchmark were to test different approaches, some alternatives could be:
RegExp.test
)However, since the focus is on comparing startsWith
and includes
, these alternative approaches might not provide additional insights.
In summary, this benchmark tests the performance difference between two string comparison methods: startsWith
and includes
. The test cases are designed to find the substring "bonjour" in a random string.