JS: For loop vs Array.indexOf (v12)

Revision 12 of this benchmark created on


Description

Testing speed of a standard for loop vs. Array.indexOf.

Preparation HTML

<script>
  var ar = new Array(10000);
  ar[2500] = 42;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
While loop - found
var i = 0, v = 43;
while (ar[i++] != v);
ready
indexOf - found
var a = ar.indexOf(43);
ready

Revisions

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