int vs. float in benchmark testing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bart Nessux

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

  • Peter Hansen

    #2
    Re: int vs. float in benchmark testing

    Bart Nessux wrote:[color=blue]
    >
    > 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()[/color]

    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

    Comment

    • Bart Nessux

      #3
      Re: int vs. float in benchmark testing

      Peter Hansen wrote:[color=blue]
      > Bart Nessux wrote:
      >[color=green]
      >>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()[/color]
      >
      >
      > Uh, yes it would, as far as it goes, but are you sure you're
      > learning something useful by doing so?[/color]

      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.


      Comment

      • Peter Hansen

        #4
        Re: int vs. float in benchmark testing

        Bart Nessux wrote:[color=blue]
        >
        > 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.[/color]

        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

        Comment

        • David E. Konerding DSD staff

          #5
          Re: int vs. float in benchmark testing

          In article <c15899$ag1$1@s olaris.cc.vt.ed u>, Bart Nessux wrote:[color=blue]
          > Peter Hansen wrote:[color=green]
          >> Bart Nessux wrote:
          >>[color=darkred]
          >>>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()[/color]
          >>
          >>
          >> Uh, yes it would, as far as it goes, but are you sure you're
          >> learning something useful by doing so?[/color]
          >
          > 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.[/color]

          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

          Comment

          • Andrew MacIntyre

            #6
            Re: int vs. float in benchmark testing

            On Fri, 20 Feb 2004, Peter Hansen wrote:
            [color=blue]
            > Bart Nessux wrote:[color=green]
            > >
            > > 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.[/color]
            >
            > Then why not get yourself some real benchmarks?[/color]

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

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

            Comment

            • David Morgenthaler

              #7
              Re: int vs. float in benchmark testing

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

              I think you'll mainly be benchmarking the 'print x' rather than the
              int/float comparison and int/float addition.
              [color=blue]
              >Bart Nessux wrote:[color=green]
              >>
              >> 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()[/color]
              >
              >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[/color]

              Comment

              Working...