Slice vs Substr vs Substring Methods

JavaScript performance comparison

Revision 40 of this test case created by Oleg2tor

Info

This is comparing the runtimes of substr, substring, and slice in a string for wrong (no spaces) date format string.

Preparation code

<script type="text/javascript">
  var str = "19700101";
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Substring
str = str.substring(0,4) + '-' + str.substring(4,6) + '-' + str.substring(6,8);
pending…
Slice
str = str.slice(0,4) + '-' + str.slice(4,6) + '-' + str.slice(6,8);
pending…
Substr
str = str.substr(0,4) + '-' + str.substr(4,2) + '-' + str.substr(6,2);
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. Here’s a list of current revisions for this page:

0 comments

Add a comment