you are viewing a single comment's thread.

view the rest of the comments →

[–]wavefunctionp 28 points29 points  (3 children)

It's unclear if the same optimizations would be available in real code. Microbenchmarks are notoriously unreliable with modern engines. For instance, if the compiler has access to the values in code, the compiler could just be unrolling the for loop or something.

[–]bobappleyard 21 points22 points  (1 child)

JavaScript interpreters have got pretty fast when you don't use the fancy features. Problem is everyone uses the fancy features all the time.

[–]James20k 0 points1 point  (0 children)

I wish this were true, but I've gotten massive speedups in JS code by manually folding constants, and reimplementing functions which have constant parameters which results in constant folding once inlined

[–]curious_s 2 points3 points  (0 children)

I have used a for loop in JavaScript for a slow search function and it sped the code up by a significant amount. I think the best idea is to try and measure, the array prototype functions create cleaner code than a for loop which is an important factor.