Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Split vs Regex for URL Path segment check
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Split
11628139.0 Ops/sec
regex
8060336.0 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const testPath = "http://foo.org/smth/teachers/ad0bfc84-3d16-46c3-948c-2f8d08976fcc/bar"; const userIdPathSegments = ['students', 'teachers']; const userIdPathSegmentRegexps = [new RegExp(/students\/(?<userId>\w+)/), new RegExp(/teachers\/(?<userId>\w+)/)];
Tests:
Split
const pathParts = testPath.split('/').filter(p => p); const userIdIndex = pathParts.findIndex(p => userIdPathSegments.some(aPN => p === aPN)); if (userIdIndex >= 0 && pathParts.length > userIdIndex + 1) { pathParts[userIdIndex + 1]; }
regex
for (let i = 0; i < userIdPathSegmentRegexps.length; i++) { const match = testPath.match(userIdPathSegmentRegexps[i]); if (Array.isArray(match) && match.length == 2 && match[1].length > 0) { return match[1]; } }