Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
startsWith vs includes()
(version: 0)
Comparing performance of:
test1 vs test2
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
test1
const str = "https://firebase.com/this/is/a/long/thing" str.includes("https://firebase")
test2
const str = "https://firebase.com/this/is/a/long/thing" str.startsWith("https://firebase")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
test1
test2
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Browser/OS:
Chrome 125 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
test1
133646776.0 Ops/sec
test2
38299920.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. **Benchmark Overview** The provided benchmark measures the performance difference between two common string methods: `includes()` and `startsWith()`. The test case uses a fixed string `"https://firebase.com/this/is/a/long/thing"` to compare the execution times of these two methods. **Options Compared** Two options are compared: 1. **`includes()`**: This method checks if a specified value (in this case, `"https://firebase"`) is present in the original string. 2. **`startsWith()`**: This method checks if the original string starts with a specified value (also `"https://firebase"`). **Pros and Cons** * `includes()`: Pros: * More flexible, as it can be used to check for any substring within the original string. * Can be used with regular expressions to perform more complex searches. Cons: * Slower than `startsWith()` due to the additional iteration required to find the matching substring. * `startsWith()`: Pros: * Faster, as it only requires a single character check at the beginning of the string. * More straightforward and efficient for simple string matching tasks. **Library Usage** None of the benchmark tests explicitly use any libraries. However, if they did, some popular JavaScript string manipulation libraries include: * Lodash: Provides various utility functions for strings, including `includes()` and `startsWith()`. * String.prototype: Built-in methods for manipulating strings in JavaScript, such as `includes()` and `startsWith()`. **Special JS Features or Syntax** None of the provided benchmark tests utilize special JavaScript features or syntax. The test cases are straightforward and focus on comparing the performance of two basic string methods. **Other Alternatives** If you were to create a similar benchmark using MeasureThat.net, you could consider adding more options, such as: * `endsWith()`: Measures the performance difference between this method and the others. * `localeCompare()`: Compares two strings according to their locale-specific collation rules. * Regular expressions: Tests the performance of different regular expression patterns for string matching. Keep in mind that each alternative would require a new benchmark definition, test case, and execution results.
Related benchmarks:
javascript startsWith() vs includes()
Js Search - String StartsWith vs Includes
check application json startswith vs includes
startsWith vs includes when no match
startsWith vs includes (when no match)
Comments
Confirm delete:
Do you really want to delete benchmark?