Sep-24-2019, 02:29 PM
(Sep-24-2019, 02:17 PM)jefsummers Wrote: Reviving this old thread, after about 10 days of waiting I still had no answer so I broke the problem apart to see where the slowdown is. It's in the conversion from integer to string. I get the integer answer in less than 1 second. But, it's a huge integer. Conversion to a string so I can display it or write it to a file takes forever.Did you get the whole number in less than 1 second? If you can send me its photo, it would be awesome (at least the first 12 and last 12 digits)! Because, turning it into a string is really complicated!
import datetime as dt start = dt.datetime.now() target = 2**34 alpha = 1<<target stop = dt.datetime.now() print(start, stop) input("Calculated value: ") start = dt.datetime.now() outstr = str(alpha) stop = dt.datetime.now() print(start, stop) input("Converted to string: ") start = dt.datetime.now() with open('c:\\Users\\summersj\\bignum.txt', 'w') as file : file.write(outstr) stop = dt.datetime.now() print(f"Wrote to file {start} {stop}")
Output:2019-09-24 10:15:24.725485 2019-09-24 10:15:25.651044 Calculated value: