HTML Preparation code:
x
 
1
<script>
2
3
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.";
4
var d=" ";
5
  
6
7
</script>
Tests:
  • split

     
    var a=s.split(d);
    var i,l=a.length,w;
    for(i=0;i<l;i++){
        w=a[i];
    };
  • for loop

     
    var i,l=s.length,w,lsp=-1;
    for(i=0;i<l;i++){
        if(s.charAt(i) == d){
            w=s.slice(lsp+1,i);
          lsp=i
        }
    };
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    split
    for loop

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36
Chrome 101 on Windows
View result in a separate tab
Test name Executions per second
split 1835794.0 Ops/sec
for loop 7551.7 Ops/sec