JS: For loop vs Array.indexOf (v259)

Revision 259 of this benchmark created by Amoki on


Description

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

Preparation HTML

<script>
  var ar = ['5252ce4ce4cfcd16f55cfa3a', '5252ce4ce4cfcd16f55cfa30', '5252ce4ce4cfcd16f55cfa31', '5252ce4ce4cfcd16f55cfa32', '5252ce4ce4cfcd16f55cfa33', '5252ce4ce4cfcd16f55cfa34', '5252ce4ce4cfcd16f55cfa35', '5252ce4ce4cfcd16f55cfa36', '5252ce4ce4cfcd16f55cfa37', '5252ce4ce4cfcd16f55cfa38'];
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
For loop
for (var i = 0; i < ar.length; i++) {
 if (ar[i] === '5252ce4ce4cfcd16f55cfa38') {
  break;
 }
}
ready
other for-loop
for (var i = 0, n = ar.length; i < n; i++) {
 if (ar[i] === '5252ce4ce4cfcd16f55cfa38') {
  break;
 }
}
ready
indexOf
var a = ar.indexOf('5252ce4ce4cfcd16f55cfa3a8');
ready

Revisions

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