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

Revision 83 of this benchmark created on


Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
Substring (long)
for (i = 0; i < longString.length; i++) {
  longString.substring(i, 10);
}
ready
Slice (long)
for (i = 0; i < longString.length; i++) {
  longString.slice(i, i + 10);
}
ready
Substr (long)
for (i = 0; i < longString.length; i++) {
  longString.substr(i, 10);
}
ready
[ ] (long)
for (i = 0; i < longString.length; i++) {
  for(j=0;j<10;j++){
    word += longString[i];
  }
  word = "";
}
ready
charAt (long)
for (i = 0; i < longString.length; i++) {
  for(j=0;j<10;j++){
    word += longString.charAt(i);
  }
  word = "";
}
ready

Revisions

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