473,326 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

int vs. float in benchmark testing

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

Jul 18 '05 #1
6 2017
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
Jul 18 '05 #2
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.
Jul 18 '05 #3
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
Jul 18 '05 #4
In article <c1**********@solaris.cc.vt.edu>, 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
Jul 18 '05 #5
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: an*****@bullseye.apana.org.au (pref) | Snail: PO Box 370
an*****@pcug.org.au (alt) | Belconnen ACT 2616
Web: http://www.andymac.org/ | Australia

Jul 18 '05 #6
On Fri, 20 Feb 2004 09:53:04 -0500, Peter Hansen <pe***@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


Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Duncan Lissett | last post by:
Is there a Python implementation of Martin Richards benchmark Bench? Be interesting to add it to these www.lissett.com/ben/exp/bench1.htm
0
by: julio | last post by:
Hello Guys, AlphaServer EV6 processor 500mhz/1Gm memory with Linux mysql> SELECT BENCHMARK(1000000,ENCODE("hello","goodbye")); +----------------------------------------------+ |...
13
by: TheKeith | last post by:
Is it just me or does opera and ie not render the float style properly? IE does a sucky job at it, but opera makes a total mess; Mozilla/Firefox renders it correctly however. I'm just trying to be...
9
by: Sisyphus | last post by:
Hi, I have some software that does the following (in an attempt to determine whether the double x, can be represented just as accurately by a float): void test_it(double x) { float y = x;...
13
by: Michele Guidolin | last post by:
Hello to everybody. I'm doing some benchmark about a red black Gauss Seidel algorithm with 2 dimensional grid of different size and type, I have some strange result when I change the computation...
7
by: Ralph Mason | last post by:
I was looking at this page http://www.garret.ru/~knizhnik/dybase/doc/dybase.html And noticed running the same code (Java ported to C# using the MS tool I expect) that the C# implementation is...
6
by: Steve | last post by:
Hi, I've developed a testing application that stores formatted results in a database. Recently it was requested that I add the ability to generate graphs from the raw, un formatted test results...
0
by: Jon Harrop | last post by:
A JVM developer called John Rose from Sun Microsystems recently claimed on a mailing list that Sun's JVM offers C-like performance whereas .NET only offers performance comparable to old JVM...
37
by: Jack | last post by:
I know one benchmark doesn't mean much but it's still disappointing to see Python as one of the slowest languages in the test: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.