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

Revision 52 of this benchmark created on


Description

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

Preparation HTML

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

Test runner

Ready to run.

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

Revisions

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