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

Revision 79 of this benchmark created by fundon on


Description

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

Preparation HTML

<script>
  var longString = "http://jsperf.com/slice-vs-substr-vs-substring-methods-long-string";
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Substring
longString.substring(5, 10);
 
ready
Slice
longString.slice(5, 10);
ready
Substr
longString.substr(5, 10);
 
ready
[ ]
longString[10];
 
ready
charAt
longString.charAt(10);
 
ready
substr
longString.substr(10, 11);
ready
substring
longString.substring(10, 11);
ready
slice
longString.slice(10, 11);
ready

Revisions

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