Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does some Ruby code run twice as fast on a 2.53GHz than on a 2.2GHz Core 2 Duo processor?
    primarykey
    data
    text
    <p>(This question attempts to find out why the running of a program can be different on different processors, so it is related to the performance aspect of programming.)</p> <p>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. Why is that? </p> <p>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> <pre><code>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 </code></pre> <p><strong>The following are just output of the program:</strong></p> <p>On 2.2GHz Core 2 Duo: (<strong>Update:</strong> Macbook identifier: MacBook3,1, therefore probably is Intel Core 2 Duo (T7300/T7500))</p> <pre><code>$ 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 </code></pre> <p>2.53GHz Intel Core 2 Duo: (<strong>Update:</strong> Macbook identifier: MacBookPro5,4, therefore probably is Intel Core 2 Duo Penryn with 3 MB on-chip L2 cache)</p> <pre><code>$ 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 </code></pre> <p>Test run on Windows 7:</p> <pre><code>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" </code></pre> <p>Intel Q6600 Quad Core 2.4GHz running Windows 7, 64-bit:</p> <pre><code>C:\&gt; ruby try.rb "1.9.2" "ruby 1.9.2p0 (2010-08-18) [i386-mingw32]" 9999999 23333331666668 Took 3.248186 seconds to run </code></pre> <p>Intel 920 i7 2.67GHz running Windows 7, 64-bit:</p> <pre><code>C:\&gt; ruby try.rb "1.9.2" "ruby 1.9.2p0 (2010-08-18) [i386-mingw32]" 9999999 23333331666668 Took 2.044117 seconds to run </code></pre> <p>It is also strange why an i7 with 2.67GHz is slower than a 2.53GHz Core 2 Duo.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload