Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > int vs. float in benchmark testing

Reply
Thread Tools

int vs. float in benchmark testing

 
 
Bart Nessux
Guest
Posts: n/a
 
      02-20-2004
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()

 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      02-20-2004
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
 
Reply With Quote
 
 
 
 
Bart Nessux
Guest
Posts: n/a
 
      02-20-2004
Peter Hansen wrote:
> 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?


Uh, yes. We're benchmarking different processors. An IBM PPC 970 does
things differently than an Intel P4. Running the same bit of Python code
on both makes for an interesting comparison. Since processors handle
ints and floats differently, it is useful for me to test them both.


 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      02-20-2004
Bart Nessux wrote:
>
> Uh, yes. We're benchmarking different processors. An IBM PPC 970 does
> things differently than an Intel P4. Running the same bit of Python code
> on both makes for an interesting comparison. Since processors handle
> ints and floats differently, it is useful for me to test them both.


Then why not get yourself some real benchmarks?

Benchmarks are a tricky thing. Unless your real code is doing
something that looks an awful lot like the above (looping and adding
1.0 to things a lot), it seems unlikely what you learn will really be
what you wanted to learn.

-Peter
 
Reply With Quote
 
David E. Konerding DSD staff
Guest
Posts: n/a
 
      02-20-2004
In article <c15899$ag1$>, Bart Nessux wrote:
> Peter Hansen wrote:
>> 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?

>
> Uh, yes. We're benchmarking different processors. An IBM PPC 970 does
> things differently than an Intel P4. Running the same bit of Python code
> on both makes for an interesting comparison. Since processors handle
> ints and floats differently, it is useful for me to test them both.


I bet (significantly) more time is being spent in the python byte code processing machinery than the
actual chip-level instructions performing the integer and floating point math, so your
processor-differential results will be masked by that.

Dave
 
Reply With Quote
 
Andrew MacIntyre
Guest
Posts: n/a
 
      02-20-2004
On Fri, 20 Feb 2004, Peter Hansen wrote:

> Bart Nessux wrote:
> >
> > Uh, yes. We're benchmarking different processors. An IBM PPC 970 does
> > things differently than an Intel P4. Running the same bit of Python code
> > on both makes for an interesting comparison. Since processors handle
> > ints and floats differently, it is useful for me to test them both.

>
> Then why not get yourself some real benchmarks?


Marc-Andre Lemburg's PyBench covers this sort thing.

--
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: (pref) | Snail: PO Box 370
(alt) | Belconnen ACT 2616
Web: http://www.andymac.org/ | Australia

 
Reply With Quote
 
David Morgenthaler
Guest
Posts: n/a
 
      02-22-2004
On Fri, 20 Feb 2004 09:53:04 -0500, Peter Hansen <>
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
float to string to float, with first float == second float Carsten Fuchs C++ 45 10-08-2009 09:47 AM
Float to int conversion by using two int variables for representation of the float variable k3n3dy C++ 15 04-20-2006 06:53 PM
Float to int conversions (was: int(float(sys.maxint)) buglet) Nick Coghlan Python 0 12-06-2004 12:12 PM
Re: float->byte->float is same with original float image. why float->ubyte->float is different??? bd C Programming 0 07-07-2003 12:09 AM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57