Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
startWith/includes
(version: 0)
Comparing performance of:
includes vs startsWith
Created:
3 years ago
by:
Registered User
Jump to the latest result
Tests:
includes
const obj = { key1: '', key2: '', key3: '', key4: '' }; Object.keys(obj) .filter((key) => key.includes('key3'))
startsWith
const obj = { key1: '', key2: '', key3: '', key4: '' }; Object.keys(obj) .filter((key) => key.startsWith('key3'))
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:
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):
Let's break down the provided benchmark and explain what is being tested. **Benchmark Overview** The benchmark measures the performance of two different string methods in JavaScript: `filter()` with the `includes()` method, and `startsWith()` with another custom implementation. **Options Compared** Two options are compared: 1. **`Object.keys(obj) .filter((key) => key.includes('key3'))`**: This option uses the `includes()` method to check if a string contains a certain substring. 2. **Custom `startsWith()` implementation**: This option implements a custom `startsWith()` method that checks if a string starts with a specific prefix. **Pros and Cons of Each Approach** 1. **`Object.keys(obj) .filter((key) => key.includes('key3'))`**: * Pros: Simple to implement, widely supported by modern browsers. * Cons: May be slower due to the overhead of `includes()` method invocation, which performs a substring search. 2. **Custom `startsWith()` implementation**: * Pros: Can be optimized for specific use cases or hardware architectures, potentially faster than using `includes()` method. * Cons: Requires manual implementation and maintenance, may not work correctly across all browsers. **Library Usage** None of the test cases use any libraries explicitly. However, the benchmark uses the `Object.keys()` method, which is a built-in JavaScript API. **Special JS Features or Syntax** The benchmark does not mention any special JavaScript features or syntax that are specific to certain versions or implementations. The code used in the benchmark is likely standard and widely supported by modern browsers. **Other Alternatives** If you want to compare other string methods, here are some alternatives: * `includes()` vs. `indexOf()`: Both methods perform substring searches, but `includes()` is generally faster and more concise. * `startsWith()` vs. `match()` or `test()`: These methods can be used to check if a string starts with a specific pattern. **Benchmark Preparation Code** The provided benchmark preparation code is empty (`"Script Preparation Code": null, "Html Preparation Code": null`). This means that the benchmark script does not perform any initialization or setup before running the test cases.
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?