Entering a very large number

bartc bc at freeuk.com
Sun Mar 25 12:30:33 EDT 2018


On 25/03/2018 16:47, Grant Edwards wrote:
> On 2018-03-25, bartc <bc at freeuk.com> wrote:
>> On 25/03/2018 02:47, Steven D'Aprano wrote:
>>
>>> The Original Poster (OP) is concerned about saving, what, a tenth of a
>>> microsecond in total? Hardly seems worth the effort, especially if you're
>>> going to end up with something even slower.
>>
>> 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.
> 
> Which adds up to 4 seconds.
> 
> Still not worth spending hours (or even a few minutes) to optimize.

If this is a program that will only ever be used by one person, and that 
person will only ever run it once, and you know that bit is executed 1M 
time and not 50M, then you might be right.

Remember that 4 seconds might be on top of dozens of other things that 
don't appear to be worth optimising.

The chances are however that a program in development might be run 
hundreds or thousands of times.

-- 
bartc



More information about the Python-list mailing list