Slice vs Substr vs Substring vs [ ] Methods (v32)

Revision 32 of this benchmark created by Lucas on


Description

This is comparing the runtimes of [ ], substr, substring, and slice in a string for large (10000 character) string size.

This revision is reversed substr, substring and slice (remove the last letter);

Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
Substring (long)
 longString.substring(0, longString.length - 1);
ready
Slice (long)
longString.slice(0, -1);
ready
Substr (long)
longString.substr(-longString.length, longString.length-1);
ready

Revisions

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