Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Split vs Regex for URL Path segment check
(version: 1)
Comparing performance of:
Split vs regex
Created:
one year ago
by:
Guest
Jump to the latest result
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]; } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Split
regex
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Split
11628139.0 Ops/sec
regex
8060336.0 Ops/sec
Related benchmarks:
mine vittu
Take last part from URL (Regex vs split)
Get last part from URL (Regex vs Split vs Substring)
contains vs regex
split vs regex onurl
re.match vs re.test vs str.startsWith vs str.indexOf
re.match vs re.test vs str.startsWith
str.match vs str.split with regex vs string input
A Spl vs Regx
Comments
Confirm delete:
Do you really want to delete benchmark?