Javascript: reduce VS for (modified)

Compare the "reduce" method with the "for" iteration method. Use case: There is an array with different numbers, we will compare the performance between the two methods to find the quantity of numbers greater than zero in the array list.
3 years ago
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Safari/605.1.15
Test name Executions per second
Number 1: use for iterator 745834.9 Ops/sec
Number 2: using reduce method 7007155.0 Ops/sec
Script Preparation code:
Tests:
  • Number 1: use for iterator

  • Number 2: using reduce method

Open this result on MeasureThat.net