Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
startswith vs includes kc
(version: 0)
Comparing performance of:
includes vs startsWith
Created:
2 years ago
by:
Guest
Go to the latest result
Tests:
includes
const str = "22264537173,co_desktop_spl_primary-over-header-1" str.includes("22264537173")
startsWith
const str = "22264537173,co_desktop_spl_primary-over-header-1" str.startsWith("22264537173")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
includes
startsWith
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; SAMSUNG SM-J810G) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/16.0 Chrome/92.0.4515.166 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 92 on Android
View result in a separate tab
Embed
Embed Benchmark Result
startsWith
4.1M/s
includes
2.9M/s
View exact numbers
Test name
Executions per second
✓
startsWith
4,103,175 Ops/sec
includes
2,924,202 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is being tested. **What is being tested?** The provided JSON represents a JavaScript microbenchmark that compares two approaches to check if a string starts with a certain substring: `str.startsWith()` and `str.includes()`. **Options compared** Two options are being compared: 1. **`str.startsWith()`**: This method checks if the string `str` starts with the specified substring. 2. **`str.includes()`**: This method checks if the string `str` contains the specified substring. **Pros and Cons of each approach** * **`str.startsWith()`**: + Pros: More efficient for strings that start with the target substring, as it can stop checking once it finds a match. + Cons: May be slower for strings that do not start with the target substring, as it still checks every character in the string. * **`str.includes()`**: + Pros: Can handle cases where the target substring is anywhere in the string, not just at the beginning. + Cons: Typically less efficient than `startsWith()` since it has to check every character in the string. **Library used** None of the provided benchmark code uses any external libraries. The tests are written purely in JavaScript. **Special JS feature or syntax** The test cases do not use any special JavaScript features or syntax, such as async/await, Promises, or modern ES6+ syntax. **Benchmark preparation code** Since no specific script preparation code is provided, we can't analyze it directly. However, the benchmark definition and individual test cases are self-contained and don't require external setup. **Other alternatives** If you wanted to measure the performance of `str.startsWith()` and `str.includes()`, other alternatives could include: * Using a JavaScript interpreter or runtime that provides built-in support for these methods (e.g., Node.js). * Writing custom loop-based implementations of these methods. * Using a benchmarking library like Benchmark.js, which provides an easy-to-use API for creating and running benchmarks. Overall, the provided benchmark is well-designed to compare the performance of two common string matching methods in JavaScript.
Related benchmarks
Deep merge lodash vs ramda vs deepmerge
Comments
Confirm delete:
Do you really want to delete benchmark?