int vs. float in benchmark testing

David David
Sat Feb 21 19:17:36 EST 2004


On Fri, 20 Feb 2004 09:53:04 -0500, Peter Hansen <peter at engcorp.com>
wrote:

I think you'll mainly be benchmarking the 'print x' rather than the
int/float comparison and int/float addition.

>Bart Nessux wrote:
>> 
>> Would adding .0 to each of the numbers below turn this into a floating
>> point test? Seems too easy.
>> 
>> def cpu_test():
>>     import time
>>     start = time.time()
>>     x = 0                               # 0.0
>>     while x < 9999999:                  # 9999999.0
>>        x = x + 1                                # 1.0
>>        print x
>>     print (time.time()-start)/60
>> cpu_test()
>
>Uh, yes it would, as far as it goes, but are you sure you're
>learning something useful by doing so?  Floats are always slower
>than ints, but you really shouldn't be concerned about speed
>anyway.
>
>The way to decide which to use is this:  if you need floating
>point because you are doing math that involves fractional values,
>then use floating point.  Otherwise use ints.  End of story.
>No performance considerations in most code.
>
>-Peter




More information about the Python-list mailing list