Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
Chrome 85
Windows
Desktop
4 years ago
Test name Executions per second
For loop, basic 4090.4 Ops/sec
While loop, basic 4199.2 Ops/sec
For loop, cached (inside for statement) 6324.0 Ops/sec
For loop, cached (outside for statement) 6270.9 Ops/sec
For loop, i-- (caching inside for loop) 6440.5 Ops/sec
For loop, i-- (caching outside for loop) 6575.9 Ops/sec
While loop, cached 6004.6 Ops/sec
While loop, i-- 6242.0 Ops/sec
forEach 12254.4 Ops/sec
Script Preparation code:
Tests:
  • For loop, basic

  • While loop, basic

  • For loop, cached (inside for statement)

  • For loop, cached (outside for statement)

  • For loop, i-- (caching inside for loop)

  • For loop, i-- (caching outside for loop)

  • While loop, cached

  • While loop, i--

  • forEach