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

Added performance benchmark. #2

Closed hiddentao closed 10 years ago

hiddentao commented 10 years ago

I wanted to know what the performance impact was so I added this in. I've added my results to the README.

The Math. functions are likely expensive compared to the rest of the code. I was able to massively speed up fast-levenshtein by expanding Math.min() into manual code. Perhaps the same can be done here. We'll never match native but I think we can get closer.

hiddentao commented 10 years ago

I take that back regarding the Math. method calls. They don't have as much impact as I thought.

ben-ng commented 10 years ago

I haven't done much optimization yet, but I think that the array allocations in fastTwoSum and extractScalar might be one source of slowness - https://github.com/ben-ng/add/blob/master/index.js#L41

If these functions are used a lot, it would be faster to statically allocate an array.