Why Ruby 1.9.2 double the speed on 2.53GHz vs 2.2GHz Core 2 Duo?

Discussion in 'Ruby' started by winter heat, Nov 1, 2010.

  1. winter heat

    winter heat Guest

    The following program will take 3.6 seconds to run on a Macbook that has
    2.2GHz Core 2 Duo, and 1.8 seconds to run on a Macbook Pro that has
    2.53GHz Core 2 Duo.

    That's a bit weird... why doubling the speed when the CPU is only 15%
    faster in clock speed? I double checked the CPU meter to make sure none
    of the 2 cores are in 100% usage (so as to see the CPU is not busy
    running something else). Could it be because one is Mac OS X Leopard
    and one is Mac OS X Snow Leopard (64 bit)? Both are running Ruby 1.9.2.


    ------------------------------------------------------------

    p RUBY_VERSION
    p RUBY_DESCRIPTION if defined? RUBY_DESCRIPTION
    n = 9_999_999
    p n

    t = 0; 1.upto(n) {|i| t += i if i%3==0 || i%5==0}; p t

    ------------------------------------------------------------

    2.2GHz Core 2 Duo

    $ time ruby 1.rb
    "1.9.2"
    "ruby 1.9.2p0 (2010-08-18 revision 29036) [i386-darwin9.8.0]"
    9999999
    23333331666668

    real 0m3.784s
    user 0m3.751s
    sys 0m0.021s

    ------------------------------------------------------------

    2.53GHz Intel Core 2 Duo

    $ time ruby 1.rb
    "1.9.2"
    "ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]"
    9999999
    23333331666668

    real 0m1.893s
    user 0m1.809s
    sys 0m0.012s

    ------------------------------------------------------------

    Test run on Windows 7:

    time_start = Time.now

    p RUBY_VERSION
    p RUBY_DESCRIPTION if defined? RUBY_DESCRIPTION

    n = 9_999_999
    p n

    t = 0; 1.upto(n) {|i| t += i if i%3==0 || i%5==0}; p t

    print "Took #{Time.now - time_start} seconds to run\n"

    ------------------------------------------------------------

    Intel Q6600 Quad Core 2.4GHz running Windows 7, 64-bit

    C:\> ruby try.rb
    "1.9.2"
    "ruby 1.9.2p0 (2010-08-18) [i386-mingw32]"
    9999999
    23333331666668
    Took 3.248186 seconds to run

    ------------------------------------------------------------

    Intel 920 i7 2.67GHz running Windows 7, 64-bit

    C:\> ruby try.rb
    "1.9.2"
    "ruby 1.9.2p0 (2010-08-18) [i386-mingw32]"
    9999999
    23333331666668
    Took 2.044117 seconds to run

    ------------------------------------------------------------

    it is also strange why an i7 with 2.67GHz is slower than a 2.53GHz Core
    2 Duo.

    --
    Posted via http://www.ruby-forum.com/.
     
    winter heat, Nov 1, 2010
    #1
    1. Advertising

  2. winter heat

    Andreas S. Guest

    winter heat wrote in post #958421:
    > "ruby 1.9.2p0 (2010-08-18 revision 29036) [i386-darwin9.8.0]"
    > "ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]"


    Some of your rubies are built with the old i386 (32 bit) instruction
    set, some with the new x86_64 (64 bit) instruction set. The latter is
    obviously faster.

    --
    Posted via http://www.ruby-forum.com/.
     
    Andreas S., Nov 1, 2010
    #2
    1. Advertising

  3. 64-bit environments are not "obviously" faster than 32-bit. In fact,
    some apps run slower when built for 64-bit environment as they end up
    moving more stuff in and out of memory, mostly zeros.

    However, in this case, the program is dealing with large Integers,
    bigger than 31 bits but smaller than 63 bits. On a 32-bit platform they
    overflow from a Fixnum to a Bignum. This means that real objects have to
    be allocated in memory to represent each value, and they have to be
    garbage-collected, whereas on the 64-bit platform they are immediate
    values.

    Try:

    $ ruby -e 'puts 23333331666668.class'

    on both machines.

    --
    Posted via http://www.ruby-forum.com/.
     
    Brian Candler, Nov 2, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TR
    Replies:
    1
    Views:
    394
    John Saunders
    Dec 14, 2004
  2. John Henry

    Better utilization of duo-core?

    John Henry, Jul 13, 2006, in forum: Python
    Replies:
    2
    Views:
    315
    Fredrik Lundh
    Jul 13, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,071
    Smokey Grindel
    Dec 2, 2006
  4. Replies:
    5
    Views:
    1,429
    Leo jay
    Nov 17, 2006
  5. jim-on-linux
    Replies:
    1
    Views:
    256
    Aaron Brady
    Dec 11, 2008
Loading...

Share This Page