Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Find substring in a long string
(version: 2)
Benchmark finding a string in a substring via several methods.
Comparing performance of:
IndexOf vs Includes vs test (regex)
Created:
one year ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var string = 'test:segment:foo-bar:EBAC7R$MTVEQV3$GWF2WF2-2025@20240902:lorem-ipsum:v1:85136c79cbf9fe36bb9d05d0639c70c265c18d37'
Tests:
IndexOf
string.indexOf(':foo-bar:')
Includes
string.includes(':foo-bar:')
test (regex)
pattern = /:foo-bar:/ pattern.test(string)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
IndexOf
Includes
test (regex)
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/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
IndexOf
246082672.0 Ops/sec
Includes
261331056.0 Ops/sec
test (regex)
12009336.0 Ops/sec
Related benchmarks:
count number of chars in a string
count number of chars in a string 2
search string by include vs index of
slice vs substr vs substring (with no end index) 1
slice vs substring (with no end index)
split some vs indexOf vs includes
Regex v split find str
regex vs split+pop vs lastIndexOf+substring
.includes() vs .test() vs .match() vs .indexOf() vs .search() fix2
Comments
Confirm delete:
Do you really want to delete benchmark?