Slice vs Substr vs Substring vs [ ] Methods

JavaScript performance comparison

Revision 75 of this test case created by

Preparation code

<script>
  var longString = "";
  // Large = 300.000
  for (var i = 0; i < 300000; i++) {
        longString += i % 10;
  }
</script>
    

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
Substring (long)

  longString.substring(30000);
  longString.substring(250000, 300000);
pending…
Slice (long)

  longString.slice(30000);
  longString.slice(250000, 300000);
pending…
Substr (long)

  longString.substr(30000);
  longString.substr(-30000, 0);
pending…
[ ] (long)
var longString2;
for (i = 30000; i < longString.length; i++) {
  longString2 = +longString[i];

}

for (i = 270000; i < longString.length; i++) {
  longString2 = +longString[i];

}
pending…
charAt (long)
var longString2;
for (i = 30000; i < longString.length; i++) {
  longString2 = +longString.charAt(i);

}

for (i = 270000; i < longString.length; i++) {
  longString2 = +longString.charAt(i);

}
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