Slice vs Substr vs Substring vs [ ] Methods

JavaScript performance comparison

Revision 79 of this test case created by fundon

Preparation code

<script>
  var longString = "http://jsperf.com/slice-vs-substr-vs-substring-methods-long-string";
</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
longString.substring(5, 10);
pending…
Slice
longString.slice(5, 10);
pending…
Substr
longString.substr(5, 10);
pending…
[ ]
longString[10];
pending…
charAt
longString.charAt(10);
pending…
substr
longString.substr(10, 11);
pending…
substring
longString.substring(10, 11);
pending…
slice
longString.slice(10, 11);
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