peterolson / BigInteger.js

An arbitrary length integer library for Javascript
The Unlicense
1.12k stars 187 forks source link

Optimization question #157

Closed gardhr closed 5 years ago

gardhr commented 6 years ago

I noticed a few instances in the codebase where equals(Integer[0]) and equals(Integer[1]) are used. Maybe just an over-optimization but wouldn't it be more efficient to use isZero() and isUnit() in those cases?

peterolson commented 6 years ago

Yes, it would be slightly faster and cleaner.

gardhr commented 6 years ago

Really interesting thing though is that, even so, this library actually runs blazingly fast!

peterolson commented 6 years ago

I've made some performance benchmarks comparing this library to other big integer libraries:

http://peterolson.github.io/BigInteger.js/benchmark/

I'd certainly pull in commits changing instances of equals(Integer[0]), although I doubt there would be any noticeable differences in performance overall. There are probably some bigger bottlenecks in the library.

gardhr commented 6 years ago

Sure, why not. While I'm at it I think I'll run the benchmarks again just to see if the effect of the optimization is even measurable. :)

gardhr commented 6 years ago

Nah, too much stochastic noise from the random sampling to tell. None of the instances seemed to be performance-critical anyway.