Array.Map vs For...loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MyrinNew
    Senior Member
    • Feb 2024
    • 5168

    #1

    Array.Map vs For...loop

    I was solving a problem and saw when I used Array.map the execution was lagging a bit. And thought to switch to using for...loop, as I was not doing any complicated calculation within map callback.


    This is the sample benchmark data I used






    6,1,4,5,3,9,0,1,9,5,1,8,6,7,0,5,5,4,4







    And I did not do anything fancy, just pushed it to an array, similar to map where is returns us a new array.





    Compared it using JS Perf and saw that for..loop is ~25 times faster than map.


    I would not be switching to for..loop because of this, a good to know when there is a slow down in the application.




    More...
Working...