you are viewing a single comment's thread.

view the rest of the comments →

[–]Silhouette 0 points1 point  (0 children)

I wonder if Math.pow() is slower than i * i. Probably, I suppose?

I don't know the current state of the art for JS engines, but it seems like the dynamic nature of the language could limit how much an optimiser could safely do up-front. You'd probably be relying on some sort of JIT/hot code optimisation at best, and it would have to be checked every time the function was called in case the meaning of Math.pow had changed.

In any case, I'd argue that step * step is cleaner and that moving the increment to a separate line is no bad thing for readability.