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 (Windows NT 10.0; Win64; x64; rv:129.0) Gecko/20100101 Firefox/129.0
Browser:
Firefox 129
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
lastIndexOf
2414932224.0 Ops/sec
split
14326296.0 Ops/sec
regex
6945606.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]