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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser:
Chrome 121
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
split
738113.2 Ops/sec
for loop
16937198.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 } };