Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Regex vs startswith and slice single
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0
Browser:
Firefox 115
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Regex
4244426.5 Ops/sec
starts with and slice
126688216.0 Ops/sec
Script Preparation code:
window.idregex = /^(?<type>shared)(?<id>.*)$/ window.str = 'shared:dfhalsdkfjhasldfiuyo324987';
Tests:
Regex
const match = str.match(idregex) const type = match?.groups.type; const id = match?.groups.id
starts with and slice
const type = 'shared'; str.startsWith(type) const id = str.slice('shared'.length)