Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
lastIndexOf vs split vs regex
testing speed
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
lastIndexOf
8229995.5 Ops/sec
split
21089102.0 Ops/sec
regex
8265705.5 Ops/sec
Script Preparation code:
var str = 'player/attack-bottom/1'
Tests:
lastIndexOf
const idx = str.lastIndexOf('/') const r1 = str.substring(0, idx) const r2 = str.substring(idx + 1, str.length)
split
const splited = str.split('/') const r1 = splited[0] const r2 = splited[splited.length - 1]
regex
const splited = str.match(/[^\/]+/g) const r1 = splited[0] const r2 = splited[splited.length - 1]