ben-ng / add

A cross-browser, numerically stable algorithm that adds floats accurately in Javascript
https://www.npmjs.org/package/add
45 stars 13 forks source link

Massive speed-up by switching to params #4

Closed hiddentao closed 10 years ago

hiddentao commented 10 years ago

An ~12x speed-up by switching from using an array parameter to a parameter list, still allowing us to pass in an array of values using .apply().

As long as we stick to well-known optimization principles regarding the use of the arguments array (see this) we should be ok.

I'm almost thinking I've done something wrong here, it can't be this much faster! would appreciate your input.

hiddentao commented 10 years ago

Ah, just seen my mistake :(

hiddentao commented 10 years ago

Sorry about that, I'd been playing around with passing arrays today (and had seen some performance improvements by changing the function signature) and so I thought that perhaps there was an opportunity here. Lesson learnt: if it's too good to be true it probably isn't true.

ben-ng commented 10 years ago

It was a good try. Optimization ends up being educated guessing at some point.