ioerror / torbirdy

Torbutton for Thunderbird and related *bird forks
BSD 2-Clause "Simplified" License
84 stars 20 forks source link

For loop optimization #19

Closed frankcash closed 8 years ago

frankcash commented 9 years ago

Optimizes the for loop.

Any part of the loop that is in the second part for(first;second;third) will be checked once per loop. It gets costly to access an object property every run through unless necessary.

arthuredelstein commented 8 years ago

I compared optimized and unoptimized loops in Firefox 42.0, and there seems to be no performance difference: https://jsperf.com/for-vs-length

arlolra commented 8 years ago

http://mrale.ph/blog/2014/12/24/array-length-caching.html

sebs commented 8 years ago

In utter ignorance of any microbenchmark, I tend to use the 'new' .map, forEach, filter etc methods. Most times I ask myself: is there really need to declare and maintain a new counter variable (or even more) in order to write this? As a bonus: map, filter etc are really a bonus on readability.

frankcash commented 8 years ago

Sorry this is a year old and I should've closed it I just forgot about it/let it go.

I've since repented and understand that microbenchmarks with any good JIT will not increase performance by an substantial degree, etc.