Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
occurrence methods speed
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/121.0.0.0 Safari/537.36
Browser:
Chrome 121
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
regex
595375.7 Ops/sec
split
26645128.0 Ops/sec
loop
1759806.9 Ops/sec
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); }