const str = "Прицеп полуприцеп";
str.startsWith("Прицеп");
const str = "Прицеп полуприцеп";
str.includes("полупр");
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
startsWith | |
includes |
Test name | Executions per second |
---|---|
startsWith | 81803896.0 Ops/sec |
includes | 42311296.0 Ops/sec |
Let's break down the benchmark and analyze what's being tested.
Benchmark Overview
The benchmark measures the performance difference between two JavaScript methods: startsWith
and includes
. Both methods are used to check if a string starts with a certain substring.
Options Compared
The options being compared are:
startsWith
includes
These two methods are part of the JavaScript String prototype and are widely supported by most modern browsers.
Pros and Cons
startsWith
:includes
:startsWith
for very short strings or when the search substring is shorter than the original string.Library Usage
There are no explicit libraries used in this benchmark. However, it's likely that the JavaScript engine being tested (e.g., V8) uses some internal libraries or optimized implementations of these methods.
Special JS Features/Syntax
None mentioned.
Other Alternatives
If you need to optimize string searching, you might consider using:
Keep in mind that these alternatives might not be necessary for most use cases, and startsWith
and includes
are usually sufficient and efficient enough.
Benchmark Results
The benchmark results show the execution rate per second (ExecutionsPerSecond) for each test case. In this case:
startsWith
: 81,403,896 executions/secondincludes
: 42,311,296 executions/secondThis suggests that startsWith
is slightly faster than includes
. However, the actual performance difference may vary depending on the specific use case and input data.
Overall, this benchmark provides a useful insight into the performance characteristics of two commonly used JavaScript string methods.