indexOf vs lastIndexOf (v5)

Revision 5 of this benchmark created by Tim Tucker on


Preparation HTML

<script>
  var s = "";
  for (var i = 0; i < 100; i++) {
   if (i === 33) s += "bar";
   else s += "foo"
  }
  s += "%";
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
indexOf
s.indexOf("bar");
ready
lastIndexOf - 0
s.lastIndexOf("bar", 0);
ready
indexOf (not found)
s.indexOf("test");
ready
lastIndexOf - 0 (not found)
s.lastIndexOf("test", 0);
ready
indexOf (at end)
s.indexOf("%");
ready
lastIndexOf - 0 (at end)
s.lastIndexOf("%", 0);
ready
lastIndexOf
s.lastIndexOf("bar");
ready
lastIndexOf (not found)
s.lastIndexOf("test");
ready
lastIndexOf (end)
s.lastIndexOf("%");
ready
charAt
s.charAt(s.length-1) === '%'
ready

Revisions

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