JS: For loop vs Array.indexOf (v70)

Revision 70 of this benchmark created on


Description

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

Preparation HTML

<script>
  var ar = [];
 for(var i = 0; i < 100000; i++){ ar[i] = i; }
</script>

Test runner

Ready to run.

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

Revisions

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