int vs. float in benchmark testing

B

Bart Nessux

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()
 
P

Peter Hansen

Bart said:
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
 
B

Bart Nessux

Peter said:
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.
 
P

Peter Hansen

Bart said:
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
 
D

David E. Konerding DSD staff

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
 
D

David Morgenthaler

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,968
Members
47,518
Latest member
TobiasAxf

Latest Threads

Top