Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
split vs for loop
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Linux; Android 13; Jelly Star Build/TP1A.220624.014; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36 EdgA/124.0.2478.64
Browser:
Chrome Mobile 124
Operating system:
Android
Device Platform:
Mobile
Date tested:
one year ago
Test name
Executions per second
split
172367.8 Ops/sec
for loop
3786313.8 Ops/sec
HTML Preparation code:
<script> var s="Since all three methods have roughly equivalent performance, my preference is to use slice. It supports extracting from the end of the string and I feel that returning an empty string when start index > stop follows the principle of least surprise better than substring's swapping of parameters. I avoid substr because of the browser inconsistency."; var re=/[\\'!"(),\-.\/:;<=>?\[\]^`{}\s‘’“”]/; </script>
Tests:
split
var a=s.split(re); var i,l=a.lenght,w; for(i=0;i<l;i++){ w=a[i]; };
for loop
var i,l=s.lenght,w,lsp=-1; for(i=0;i<l;i++){ if(re.test(s.charAt(i))){ w=s.slice(lsp+1,i); lsp=i } };