Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.113 Safari/537.36
Chrome 53
Windows
Other
8 years ago
Test name Executions per second
Basic for loop 8156.5 Ops/sec
For loop but caching the length 630214.7 Ops/sec
While loop that imitates a for loop 8119.5 Ops/sec
While loop that imitates a for loop caching len 627630.3 Ops/sec
While loop in reverse simplifying the test 619832.8 Ops/sec
While looping by popping values 6114921.0 Ops/sec
for ... in loop 4116109.8 Ops/sec
for ... in loop with integer test 3842051.0 Ops/sec
For loop testing on existence rather than lengt 6594243.0 Ops/sec
For loop testing on existence plus array lookup 5880909.5 Ops/sec
For testing on existence rather than length array 6038332.0 Ops/sec
For reference 7409488.0 Ops/sec
Array.forEach() native implementation. 5811872.0 Ops/sec
For reference against forEach() 6668406.5 Ops/sec
Script Preparation code:
Tests:
  • Basic for loop

  • For loop but caching the length

  • While loop that imitates a for loop

  • While loop that imitates a for loop caching len

  • While loop in reverse simplifying the test

  • While looping by popping values

  • for ... in loop

  • for ... in loop with integer test

  • For loop testing on existence rather than lengt

  • For loop testing on existence plus array lookup

  • For testing on existence rather than length array

  • For reference

  • Array.forEach() native implementation.

  • For reference against forEach()