Archive for the ‘JavaScript’ Category

Optimizing JavaScript is harder than ever

2011-06-11

We’ve all got our favorite browser. And while developing for the web we test in that one browser first. Optimizing JavaScript for one browser only is a tempting idea. I mean … how much difference could there be between browser engines anyway?

Let’s use the Fibonacci sequence as an example. I wrote six different versions to calculate it. Obviously the naive, recursive way of calculating it is the slowest, but that is where similarities between browsers end. Internet explorer seems to be faster at looping than rounding numbers. And Chrome seems to favor local variables over global ones so much it doesn’t mind doing a lot more calculations.