Slice vs Substr vs Substring Methods (v40)

Revision 40 of this benchmark created by Oleg2tor on


Description

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

Preparation HTML

<script>
  var str = "19700101";
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Substring
str = str.substring(0,4) + '-' + str.substring(4,6) + '-' + str.substring(6,8);
ready
Slice
str = str.slice(0,4) + '-' + str.slice(4,6) + '-' + str.slice(6,8);
ready
Substr
str = str.substr(0,4) + '-' + str.substr(4,2) + '-' + str.substr(6,2);
ready

Revisions

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