Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
startswith vs includes vs substring
(version: 0)
Comparing performance of:
includes vs startsWith vs substring
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
includes
const str = "https://firebase.com/this/is/a/long/thing" str.includes("firebase")
startsWith
const str = "https://firebase.com/this/is/a/long/thing" str.startsWith("https://firebase")
substring
const str = "https://firebase.com/this/is/a/long/thing" str.substring(0,3) === "https://firebase"
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
includes
startsWith
substring
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided benchmark measures the performance of three string manipulation methods: `startsWith`, `includes`, and `substring`. These methods are commonly used in web development for working with strings. **String Manipulation Methods Compared** The benchmark compares the performance of these three methods: 1. **`startsWith`**: Returns `true` if the string starts with the specified value. 2. **`includes`**: Returns `true` if the string includes the specified value. 3. **`substring`**: Extracts a portion of the string, starting from a specified index. **Options Compared** The benchmark compares these three methods using different options: * `startsWith`: uses the `startsWith()` method with the option to ignore case (default) and trim leading/trailing whitespace (optional). * `includes`: uses the `includes()` method with the option to ignore case (default) and trim leading/trailing whitespace (optional). * `substring`: uses the `substring()` method with the option to start from a specified index. **Pros and Cons of Each Approach** Here's a brief summary of the pros and cons of each approach: 1. **`startsWith`**: Pros: * Fastest performance among the three methods. * Can be used for pattern matching. Cons: * May not work as expected if the string is modified after comparison. 2. **`includes`**: Pros: * More flexible than `startsWith`, can match substrings. Cons: * Slower performance compared to `startsWith`. 3. **`substring`**: Pros: * Can be used for extracting a portion of the string. Cons: * Slower performance compared to `startsWith` and `includes`. **Library Used** None. **Special JS Feature or Syntax** There is no special JavaScript feature or syntax used in this benchmark. **Benchmark Preparation Code** The provided JSON does not contain any script preparation code, but it's assumed that the JavaScript engine being tested will execute the provided benchmark definition code. **Other Alternatives** For string manipulation methods, other alternatives include: 1. **`indexOf()`**: Similar to `includes()`, but returns the index of the first occurrence instead of a boolean value. 2. **`lastIndexOf()`**: Similar to `startsWith()`, but searches from the end of the string instead of the start. 3. **`replace()`**: Replaces all occurrences of a pattern with another value. Keep in mind that these alternatives may have different performance characteristics and use cases compared to the methods tested in this benchmark.
Related benchmarks:
Deep merge lodash vs ramda vs deepmerge
Deep merge lodash vs ramda vs deepmerge latest
lodash.merge vs deepmerge
Deep merge lodash 4.6.2 vs ramda vs deepmerge
IndexOf vs Includes in string - larger string edition
Comments
Confirm delete:
Do you really want to delete benchmark?