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 (iPhone; CPU iPhone OS 17_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Mobile/15E148 Safari/604.1
Browser:
Mobile Safari 17
Operating system:
iOS 17.4.1
Device Platform:
Mobile
Date tested:
2 years ago
Test name
Executions per second
split
764698.4 Ops/sec
for loop
19401914.0 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 } };