Slice vs Substr vs Substring Methods (v61)

Revision 61 of this benchmark created 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 = "";
  // Large = 10,000
  for (var i = 0; i < 23; 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, i+1);
}
ready
Slice
for (i = 0; i < longString.length; i++) {
  longString.slice(i, i + 1);
}
ready
Substr (short)
for (i = 0; i < longString.length; i++) {
  longString.substr(i, 1);
}
ready
Substring.call (long)
for (i = 0; i < longString.length; i++) {
  String.prototype.substring.call(longString, i, i+1);
}
ready
Substr.call (short)
for (i = 0; i < longString.length; i++) {
  String.prototype.substr.call(longString, i, i+1);
}
ready
Slice.call
for (i = 0; i < longString.length; i++) {
  String.prototype.slice.call(longString, i, i + 1);
}
ready

Revisions

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