Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
regex-vs-startswith
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:135.0) Gecko/20100101 Firefox/135.0
Browser:
Firefox 135
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
one year ago
Benchmark engine:
Benchmark.js
startsWith
52.8M/s
regex
15.4M/s
View exact numbers
Test name
Executions per second
✓
startsWith
52,776,428 Ops/sec
regex
15,448,784 Ops/sec
Script Preparation code:
window.baseAction = 'MY_ACTION' window.actionRegularExpression = /^MY_ACTION_(\w+)_(?<=_)(.*)$/i; window.baseString = 'MY_ACTION_QUESTION_START_my-first-question';
Tests:
regex
let [, action, id] = actionRegularExpression.exec(baseString)
startsWith
let action; let id; if(baseString.startsWith(baseAction)){ const lastUnderscore = baseString.lastIndexOf('_'); action = baseString.substring(baseAction.length + 1, lastUnderscore) id = baseString.substring(lastUnderscore + 1) }