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:
one year ago
by:
Guest
Jump 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:
one year 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
Test name
Executions per second
includes
2924201.5 Ops/sec
startsWith
4103175.0 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
Deep merge lodash vs ramda vs deepmerge latest
Deep merge lodash 4.12.21 vs ramda 0.27.1
Deep merge lodash 4.12.21 vs ramBda 6.9.0
Deep merge lodash 4.6.2 vs ramda vs deepmerge
Comments
Confirm delete:
Do you really want to delete benchmark?