Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
includes vs slice vs startsWith
(version: 0)
Comparing performance of:
includes vs slice vs startsWith
Created:
one year ago
by:
Registered User
Jump to the latest result
Tests:
includes
const str = "#/test/this/url" str.includes("#/")
slice
const str = "#/test/this/url" str.slice(0,2) === "#/"
startsWith
const str = "#/test/this/url" str.startsWith("#/")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
includes
slice
startsWith
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Browser/OS:
Chrome 127 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
includes
165900256.0 Ops/sec
slice
174515888.0 Ops/sec
startsWith
147730720.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview of the Benchmark** The provided benchmark, "includes vs slice vs startsWith", is designed to compare the performance of three different string methods: `includes`, `slice`, and `startsWith`. These methods are commonly used in JavaScript to manipulate strings. **Options Being Compared** 1. **`includes`**: This method checks if a substring exists within a string. 2. **`slice`**: This method returns a new string that is a subset of the original string, starting from a specified index and ending at a specified length. 3. **`startsWith`**: This method checks if a string starts with a specified value. **Pros and Cons of Each Approach** 1. **`includes`**: * Pros: Easy to read and write, straightforward implementation. * Cons: May be slower than other methods for large strings or frequent substring searches. 2. **`slice`**: * Pros: Can be faster than `includes` for substring searches, as it returns a new string instead of modifying the original. * Cons: Requires specifying an index and length, which can lead to errors if not done correctly. 3. **`startsWith`**: * Pros: Similar performance to `slice`, with the added benefit of only checking the first character. * Cons: May be slower than `includes` for very large strings or substring searches. **Library Usage** None of the provided benchmark test cases use external libraries, but it's worth noting that some JavaScript engines may have built-in optimizations or features that can affect performance. **Special JS Features/Syntax (Not applicable)** There are no special JS features or syntax used in these benchmark test cases. **Other Alternatives** For string manipulation, developers often consider other methods like: 1. **`indexOf()`**: Similar to `includes`, but returns the index of the first occurrence instead of a boolean result. 2. **`substr()`**: Returns a subset of the original string using an index and length. 3. **`substring()`**: Returns a subset of the original string, similar to `slice`. 4. **Regular Expressions (regex)**: Can be used for more complex string matching and manipulation. These alternatives may offer different trade-offs in terms of performance, readability, or maintainability, depending on the specific use case.
Related benchmarks:
javascript startsWith() vs includes()
Js Search - String StartsWith vs Includes
startswith vs slice 2123213
check application json startswith vs includes
equals vs includes (one value)
Comments
Confirm delete:
Do you really want to delete benchmark?