Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Split vs Regex vs Contains
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:132.0) Gecko/20100101 Firefox/132.0
Browser:
Firefox 132
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
split
3291367.0 Ops/sec
regex
3419045.0 Ops/sec
string includes
13436308.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+)/)]; const userIdPathSegments2 = ['/students/', '/teachers/'];
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) { match[1]; } }
string includes
for (let i = 0; i < userIdPathSegments2.length; i++) { if (testPath.includes(userIdPathSegments2[i])) { testPath.includes(userIdPathSegments2[i] + "ad0bfc84-3d16-46c3-948c-2f8d08976fcc"); } }