Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Split vs Regex vs Contains V2
(version: 1)
Comparing performance of:
split vs regex vs string includes
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+)/)]; 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++) { const segment = userIdPathSegments2[i]; const index = testPath.indexOf(segment); if (index >= 0 && index + segment.length < testPath.length) { return testPath.endsWith(segment + "ad0bfc84-3d16-46c3-948c-2f8d08976fcc") || testPath.includes(segment + "ad0bfc84-3d16-46c3-948c-2f8d08976fcc" + '/'); } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
split
regex
string includes
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; rv:132.0) Gecko/20100101 Firefox/132.0
Browser/OS:
Firefox 132 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
split
3904813.0 Ops/sec
regex
4728635.5 Ops/sec
string includes
1769021.8 Ops/sec
Related benchmarks:
Get last part from URL (Regex vs Split vs Substring)
lorem issfaacsascsafsaf
contains vs regex
String.match 4
str.match / str.split
str.match vs str.split with regex vs string input
A Spl vs Regx
Split vs Regex for URL Path segment check
Split vs Regex vs Contains
Comments
Confirm delete:
Do you really want to delete benchmark?