JS: For loop vs Array.indexOf (v43)

Revision 43 of this benchmark created by Andrei Zharau on


Setup

var ar = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

Test runner

Ready to run.

Testing in
TestOps/sec
For loop
if (i in ar) {
for (var i = 0, l = ar.length; i < l; i++) {
 if (ar[i] === 5) {
  break;
 }
}
}
ready
indexOf
var a = ar.indexOf(5);
ready

Revisions

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