Slice vs Substr vs Substring (v98)

Revision 98 of this benchmark created on


Description

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

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
while (longString.length > 0) {
  longString = longString.substring(1);
}
ready
Substr
while (longString.length > 0) {
  longString = longString.substr(1);
}
ready
Slice
while (longString.length > 0) {
  longString = longString.slice(1);
}
ready
Split
while (longString.length > 0) {
  longString = longString.split(1)[1];
}
ready

Revisions

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