Re:A Million Digits of Pi in 9 Lines of JavaScript
by simonbw on Thursday September 12, 2019 @07:20PM
(#20957539)
It's not just the comparisons, it's the additions, multiplications and divisions too. When you enter 10,000, each iteration of the loop is working with numbers 10,000 digits long. When you enter 100,000, each iteration is working with numbers 100,000 digits long, which I imagine makes every operation slower.
[ Parent
| on HN ]
Re:A Million Digits of Pi in 9 Lines of JavaScript
by soulofmischief on Friday September 13, 2019 @02:01AM
(#20959574)
A number fills the same space in your registers regardless of size, up until the max size, at which point it must be split into multiple operations, and that's when it takes longer.