Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
occurrence methods speed
(version: 0)
Comparing performance of:
regex vs split vs loop
Created:
one year ago
by:
Guest
Jump to the latest result
Tests:
regex
const escapedText = '\ P'.replace(/[.|*|+|?|^|$|{|}|(|)|[|]|\||\\]/g, '\\$&'); const searchRegex = new RegExp(escapedText, 'gi'); const count = ('\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P'.match(searchRegex)).length;
split
const count = ('\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P'.split('\ P')).length;
loop
const string = '\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P\ P'; const searchFor = '\ P'; let count = 0; let pos = string.indexOf(searchFor); while (pos > -1) { ++count; pos = string.indexOf(searchFor, ++pos); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
regex
split
loop
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/121.0.0.0 Safari/537.36
Browser/OS:
Chrome 121 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
regex
595375.7 Ops/sec
split
26645128.0 Ops/sec
loop
1759806.9 Ops/sec
Related benchmarks:
Fixed: Performance of uniqueBy using new Map or reducing to an object, also comparing for..in and Object.values for extracting values - More3
SortingTests
Traverse Elements in DOM tree 3
Lodash#uniq + Native
uniq-vs-uniqBy-even-bigger-objects
Comments
Confirm delete:
Do you really want to delete benchmark?