Substring Extraction Methods (middle to end) (substring, substr, slice) (v5)

Revision 5 of this benchmark created by Jacob on


Preparation HTML

<script>
  var str = "This is going to be a 1000 character string: ";
  var lengthToAdd = 1000 - str.length;
  var i;
  for (i=0; i < lengthToAdd; i++)
    str += "X"
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
substring
str.substring(0,999);
ready
slice
str.split('').slice(0,999).join('');
ready
substr
str.substr(0,999);
ready
Regex
str.match(/^.{1000}/);
ready

Revisions

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