osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Entering a very large number


Am 25.03.18 um 14:32 schrieb bartc:
> Using CPython on my machine, doing a string to int conversion that 
> specific number took 200 times as long as doing a normal assignment.
> 
> That conversion took 4 microseconds.
> 
> Not significant if it's only done once. But it might be executed a 
> million times.

Honestly, why should it be executed a million times? Do you have a 
million different 400 digit numbers as constants in your code? If so, I 
suggest to store them in a database file accompanied with the code.

If there are few different only, then don't do the conversion a million 
times. Convert them at module initialization and assign them to a global 
variable.

	Christian