Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
string start with method startsWith Vs. indexOf Vs. String Array
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/134.0.0.0 Safari/537.36 Edg/134.0.0.0
Browser:
Chrome 134
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
startsWith
171.6 Ops/sec
indexOf
157.7 Ops/sec
String Array
166.0 Ops/sec
Script Preparation code:
window.testStr = 'mt-asjhbfdjasasdkbfas'; window.counter = 0; window.testTimes = 1e5;
Tests:
startsWith
window.counter = 0; for (let index = 0; index < testTimes; index++) { if (testStr.startsWith('mt-')) { counter++; } }
indexOf
window.counter = 0; for (let index = 0; index < testTimes; index++) { if (testStr.indexOf('mt-') === 0) { counter++; } }
String Array
window.counter = 0; for (let index = 0; index < testTimes; index++) { if (testStr[0] === 'm' && testStr[1] === 't' && testStr[2] === '-') { counter++; } }