Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
startswith vs includes test
(version: 0)
Comparing performance of:
includes vs startsWith
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
includes
const str = "https://firebase.com/this/is/a/long/thing" str.includes("this/is/a")
startsWith
const str = "https://firebase.com/this/is/a/long/thing" str.startsWith("this/is/a")
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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Browser/OS:
Chrome 122 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
includes
173230544.0 Ops/sec
startsWith
105686176.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. The provided JSON represents a benchmark test comparing two string comparison methods in JavaScript: `str.includes()` and `str.startsWith()`. We'll break down what's being tested, the pros and cons of each approach, and some additional considerations. **What's being tested?** In this benchmark, two identical strings are created using template literals: ```javascript const str = "https://firebase.com/this/is/a/long/thing"; ``` The `includes()` test checks if the string contains a specific substring: `"this/is/a"`. The `startsWith()` test checks if the string starts with a specific prefix: `"this/is/a"`. **Options compared** We have two options being tested: 1. **`str.includes()`**: This method searches for the specified substring within the entire string. 2. **`str.startsWith()`**: This method checks if the string starts with the specified prefix. **Pros and Cons of each approach** * `includes()`: + Pros: More flexible, as it can search for any substring within the string. + Cons: May be slower due to the additional overhead of searching for a specific position in the string. * `startsWith()`: + Pros: Faster, since it only needs to check if the first few characters match the prefix. + Cons: Less flexible, as it requires an exact matching prefix. **Library and its purpose** There is no library being used in this benchmark. The JavaScript engine is doing all the heavy lifting. **Special JS feature or syntax** The benchmark uses template literals (`\r\n`) to create a multi-line string. Template literals are a modern JavaScript feature introduced in ECMAScript 2015, which allows embedding expressions within string literals. **Other alternatives** For comparison purposes, other string comparison methods could be used: * `indexOf()`: Searches for the specified substring and returns its index. * `slice()`: Returns a new string that includes the specified substring (starting from the beginning). However, these alternatives are not being tested in this specific benchmark. In conclusion, this benchmark is designed to compare the performance of two JavaScript string comparison methods: `str.includes()` and `str.startsWith()`. The results will indicate which method is faster for searching within a string.
Related benchmarks:
javascript startsWith() vs includes()
javascript startsWith() vs includes() for longer string
Js Search - String StartsWith vs Includes
check application json startswith vs includes
startsWith vs includes (when no match)
Comments
Confirm delete:
Do you really want to delete benchmark?