Slice vs Substr vs Substring

JavaScript performance comparison

Revision 98 of this test case created by

Preparation code

<script>
  var longString = "";
  // Large = 10,000
  for (var i = 0; i < 10000; 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
while (longString.length > 0) {
  longString = longString.substring(1);
}
pending…
Substr
while (longString.length > 0) {
  longString = longString.substr(1);
}
pending…
Slice
while (longString.length > 0) {
  longString = longString.slice(1);
}
pending…
Split
while (longString.length > 0) {
  longString = longString.split(1)[1];
}
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