Generic base version - #9
Conversation
…typically base 1000000). This significantly speeds up all operations (by quite a few factors). Also Made division by relatively low divisor numbers much faster. Extended tests to include a few choice big number operations.
… 2 to 2^25, the latter fully optimising the procedures. Division logic improved yet more for further performance gains
|
Hi Dominic, I'd be happy to integrate this improvement. Can you please run eslint against your PR? |
|
Hi Alex, OK did that, but, to be honest, I'm not sure you should bother... I took up a rather unhealthy interest in the implementation of all this and became obsessed in understanding how http://mikemcl.github.io/bignumber.js managed to make his library as fast as it was. Although it is a comprehensive library it is completely unfathomable code-wise (unlike yours)! I've ended up making wholesale changes to your library in order to get the performance up to spec. Which I've got in this branch: https://github.com/dthwaite/bignumber.js.git#master. I doubt you'd want to take this either as you won't recognise most of your code! But the good news is Trouble is it's still of a comparable speed to Mike's. And Mike is still twice as fast for multiplication which bugs me. But for division (which is where I focussed my attention) I have triumphed as I finally cracked on the right algorithm and it is now 3 or 4 times faster even than Mike's. So I can retire at peace! You can check out my routine in that branch if you like, but I think this is about as fast as you'd ever get it in a JS environment. You can have the master branch if you want, which would make your claim: "It does one thing, implementing only the main arithmetic operations for big integers, but it does it very well and very fast" have some credibility :-) All the best Dom P.s. I actually got into all this to learn and understand GitHub workflow! Travis CI is awesome! |
|
Oh, I appear to have created 2 "master" branches (still got a lot to learn) the one I'm referring to above is 'Master' with a capital M! https://github.com/dthwaite/bignumber.js.git#Master |
|
Hi Dom, Thanks for doing this! You've highlighted some great performance improvements. The purpose of the library is to be both concise and fast. I want to integrate a part of the changes, while still keeping the codebase small and simple, so I may cherry-pick multiple improvements. |
|
Yeah, I think that is most sensible. Have fun Dom On 15 Mar 2016, at 19:38, Alexandru Bardaș notifications@github.com wrote:
|
Hi Alex,
Actually, I couldn't resist doing the job properly and this branch now works for ANY base. Even base 2!
I've liberally commented, but you should find that this is faster still - if you choose a base which is a power of 2 (the best option) that will ensure division is as fast as it can be.
If you run your performance tests against different bases, it would be interesting to see what results you get. If you set the base to 10 (what you had hard coded before), then it should be the same except that even the division would be about twice as fast I reckon.
Anyway, these are slightly more dramatic changes and include a few other performance enhancements.
Dominic