Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
check application json startswith vs includes
(version: 0)
Comparing performance of:
includes vs startsWith
Created:
2 years ago
by:
Registered User
Jump to the latest result
Tests:
includes
const str = "application/json; charset=utf-8" str.includes("application/json")
startsWith
const str = "application/json; charset=utf-8" str.startsWith("application/json")
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
includes
1308550656.0 Ops/sec
startsWith
19261588.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in the provided benchmark. **Benchmark Description:** The benchmark is testing two approaches for checking if a string starts with or includes another substring: 1. `str.startsWith("application/json")` 2. `str.includes("application/json")` **Options Compared:** The two options are being compared, which means we're evaluating their performance in this specific scenario. **Pros and Cons of Each Approach:** **`startsWith`:** Pros: * More efficient for strings that start with the specified substring, as it only needs to check the first few characters. * Can be optimized by checking if the string is shorter than the prefix length. Cons: * May return false positives if the string contains the specified substring elsewhere (e.g., "application/json; charset=utf-8"). * Doesn't handle edge cases like empty strings or null inputs well. **`includes`:** Pros: * Returns true for any occurrence of the substring within the string, including non-contiguous matches. * Handles edge cases like empty strings and null inputs correctly. Cons: * May be slower than `startsWith` for short strings that start with the specified substring, due to the need to scan the entire string. * Can lead to false positives if the string contains the specified substring elsewhere (e.g., "application/json; charset=utf-8"). **Library Used:** None of the provided benchmark definitions use a library explicitly. However, it's worth noting that `startsWith` and `includes` are built-in JavaScript methods. **Special JS Features/Syntax:** There aren't any special JS features or syntax used in this benchmark. The focus is on comparing two straightforward string comparison methods. **Other Alternatives:** If you wanted to test alternative approaches, here are a few options: * Using regular expressions (`RegExp.test` or `String.prototype.match`) * Using a custom implementation with a loop or recursion * Using a different language or platform (e.g., C++ or Java) for the benchmarking Keep in mind that each of these alternatives would require significant changes to the benchmark definition and test setup.
Related benchmarks:
javascript startsWith() vs includes()
Js Search - String StartsWith vs Includes
startsWith vs includes (when no match)
equals vs includes (one value)
Comments
Confirm delete:
Do you really want to delete benchmark?