Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
lastIndexOf vs split vs regex v2
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
Benchmark engine:
Benchmark.js
regex
13.9M/s
split
12.8M/s
lastIndexOf
8.2M/s
View exact numbers
Test name
Executions per second
✓
regex
13,865,260 Ops/sec
split
12,760,170 Ops/sec
lastIndexOf
8,151,700 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.slice(-1).join('/') const r2 = splited[splited.length - 1]
regex
const [_, r1, r2] = str.match(/(.+)\/(\d+)$/)