Slice vs Substr vs Substring Methods

JavaScript performance comparison

Revision 70 of this test case created by

Preparation code

<p id='nfo'></p>
<script>
  var str = "",
      len = 1e6,
      start = 10; 
  while (len--) {
        str += len;
  }
  document.getElementById('nfo').innerHTML = '"str" is ' + str.length + ' characters in length';
</script>
    

Preparation code output

<p id='nfo'></p>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Substr
str.substr(start);
pending…
Substring
str.substring(start);
pending…
Slice
str.slice(start);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments