0

This question already has an answer here:

I was benchmarking if it is worth to put loop inside a callback function so I tested fourth order Runge-Kutta of on y'=y in C++, all with gcc 5.1 on Ubuntu with compilation command

g++ -std=c++11 -O3 -march=native --fast-math test.cpp

The Runge-Kutta loop

double dt=(t_end-t_0)/N;
auto y=y_0;
auto t=t_0;
for(size_t k=0;k<N;++k)
    {
    auto k_1=f(k*dt, y);
    auto k_2=f(k*dt + 0.5*dt, y + 0.5*dt*k_1);
    auto k_3=f(k*dt + 0.5*dt, y + 0.5*dt*k_2);
    auto k_4=f(k*dt + dt, y + dt*k_3);

    y+=dt*(k_1 + 2*k_2 + 2*k_3 + k_1)/6.0;
    }

return y;

Inlining was achieved by a template and a function object. For dynamic binding a function pointer was used.

The Pentium M

Specs as given by /proc/cpuinfo

cpu family      : 6
model           : 13
model name      : Intel(R) Pentium(R) M processor 1.73GHz
stepping        : 8
microcode       : 0x20

Frequency from sudo cpufreq-info

current policy: frequency should be within 800 MHz and 1.73 GHz.
                The governor "userspace" may decide which speed to use
                within this range.
current CPU frequency is 1.73 GHz (asserted by call to hardware).

Results

                  ODE solution       exp(1)             diff                   Execution time
Function pointer  2.718281828037378  2.718281828459045  -4.21667145644733e-10  53321972
Inlined call      2.718281828037378  2.718281828459045  -4.21667145644733e-10  19916460

The Prescott:

Specs as given by /proc/cpuinfo

cpu family      : 15
model           : 4
model name      : Intel(R) Pentium(R) 4 CPU 3.40GHz
stepping        : 3
microcode       : 0x5

Frequency from sudo cpufreq-info

current policy: frequency should be within 2.80 GHz and 3.40 GHz.
                The governor "userspace" may decide which speed to use
                within this range.
current CPU frequency is 3.40 GHz.

Results

                  ODE solution       exp(1)             diff                   Execution time
Function pointer  2.718281828037378  2.718281828459045  -4.21667145644733e-10  70811683
Inlined call      2.718281828037378  2.718281828459045  -4.21667145644733e-10  19928642

Comparison and question

So the Prescott performs no better (it seems to be much worse), than the much lower clocked Pentium M. Sure, Prescott had a very long pipeline, but my code is highly predictable since N=2^30. So what makes the Prescott that slow despite its high CPU frequency?

marked as duplicate by bwDraco, Ramhound, Karan, James P, Nifle May 9 '15 at 10:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @DragonLord But these two machines are booth from 2005 – user877329 May 7 '15 at 19:19
  • @user877329 - Answer still applies. The newer processors are able to perform more instructions per clock cycle, even if they have a slower clock cycle, that means more instructions will completed faster. The generation gap between some intel processors are pretty significant. – Ramhound May 7 '15 at 19:20
  • 2
    The Pentium M is a more power-efficient architecture which formed the basis for the Core 2 series. It was optimized for high performance per clock, so that good performance can be delivered with lower clock rates. Lower clock rates mean lower power consumption, especially when the difference is between 3.4 and 1.73 GHz. – bwDraco May 7 '15 at 19:20
  • @ user877329: But they are completely different otherwise. The P-mobile is derrivated from a relative efficient (for the time) CPU and optimised to do well with low power (read: lower frequencies). The P4 was designed to run at very high speeds and much efficiency was sacrificed. The result is about the same speed for a 3GHz P4 and a P-m 740 *at 1.7GHz) – Hennes May 7 '15 at 19:21
  • You already seemed to be aware of much of this, an image for me: pbs.twimg.com/media/CEbMHK8WEAAD4Ee.jpg – Hennes May 7 '15 at 19:24