Slice vs Substr vs Substring Methods (v45)

Revision 45 of this benchmark created on


Description

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

Preparation HTML

<script type="text/javascript">
  var smallString = "";
  // Small = 100
  for (var i = 0; i < 100; i++) {
        smallString += i % 10;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Substring (small)
for (i = 0; i < smallString.length; i++) {
  smallString.substring(i, i + 1);
}
ready
Slice (small)
for (i = 0; i < smallString.length; i++) {
  smallString.slice(i, i + 1);
}
ready
Substr (small)
for (i = 0; i < smallString.length; i++) {
  smallString.substr(i, 1);
}
ready

Revisions

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