09 May 2005

JavaScript Speederisation

In writing megs and megs of JS, you often come to a junction of two ways of doing things, and wonder 'mm, which is faster?'. For example - lookup tables vs recalcuating the desired value; we're taught that lookup tables are the right way to do things, but how can we be sure? JS is so high-level that all sorts of inefficiencies may exist, and for very large lookup tables, the increased load time may not be worth it.

Well, this is what Jeff Greenburg's JavaScript Optimization Guide addresses, and despite the fact that it's getting on a bit (Mozilla/FireFox is much much faster these days), it's still a required read for anyone into this sort of thing.

Further, if you feel like benchmarking your own JS functions, bodytag has a JS Benchmarker, built just for that purpose (well, that's not entirely true - originally I just wanted to see if i^2 was faster than i*i, but things sort of went out of hand).

1 comment:

Anonymous said...

" I just wanted to see if i^2 was faster than i*i "

o_O I hope you don't mean that in your mind i^2 and i*i does the same thing. Because they do not. For those you think otherwise, let's remind that the first statement is a binary operator and has absolutely nothing to do with the second one.