Reputation: 11100
I noticed that square roots are pretty fast in python.
import time
a = time.time()
print((1234567891011121314151617181920**8)**0.5)
d = time.time()-a
print(d)
output:
2.32305723559e+120
0.0150001049042
That's a 200+ digit number in under 0.1 second!
So what's the algorithm behind all this?
Upvotes: 0
Views: 321
Reputation: 76683
CPython is just calling the C intrinsic pow
in this case, letting the compiler do whatever it wants with it. How to: pow(real, real) in x86 is one example of somewhere explaining a fast implementation of pow
at a processor level.
Upvotes: 4