JS: For loop vs Array.indexOf (bugfix) (v230)

Revision 230 of this benchmark created by x on


Description

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

Preparation HTML

<script>
  var ar = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
var as = ['ooa','stnh','sts', 'stshts', 'sthss', 'zwmz', 'kjq', 'wvmz', 'snthsnt', 'stnhsnt', 'rclh', 'zvwmzm', 'wzm', 'rix',' lsm', 'stb', 'wzm', 'lrcg', 'mn', 'yf', 'gc','rl','lcr','r/',' stsh', 'zwm','zwm','snth', 'ssss',' stn','132','321','546','654','789','987','96','u.6','oeu','oeau','aoeu','eq'];
</script>

Test runner

Ready to run.

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

Revisions

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