Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
indexOf vs startsWidth vs includes
compare javascript string matching options
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser:
Chrome 121
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
indexOf (start)
3732.1 Ops/sec
indexOf (end)
3729.3 Ops/sec
startsWith (start)
2292.4 Ops/sec
startsWith (end)
3430.0 Ops/sec
includes (start)
3705.3 Ops/sec
includes (end)
3708.8 Ops/sec
Script Preparation code:
var sub = "(sub)"; var textsStart = []; var textsEnd = []; for(var i = 0; i < 10000; i++) { textsStart.push(`${sub} My ${i} test sample which contains sub at the end`) textsEnd.push(`My ${i} test sample which contains sub at the end ${sub}`) }
Tests:
indexOf (start)
for(const textStart of textsStart) textStart.indexOf(sub)
indexOf (end)
for(const textEnd of textsEnd) textEnd.indexOf(sub)
startsWith (start)
for(const textStart of textsStart) textStart.startsWith(sub)
startsWith (end)
for(const textEnd of textsEnd) textEnd.startsWith(sub)
includes (start)
for(const textStart of textsStart) textStart.includes(sub)
includes (end)
for(const textEnd of textsEnd) textEnd.includes(sub)