Forum > Unix

[SOLVED] Pascal performance on polynomial benchmark slower than expected

<< < (2/6) > >>

marcov:
Benchmarking rows of code that can be reduced compiletime to the answer is always a risk. Some compiler might bother to optimize such microbenchmark more than others, but that's hardly a measure of realworld performance.

Try to make the number of iterations or some other crucial number something that is read from a textfile to avoid this.

With that improvement, it is still a microbenchmark (since still a single procedure in a single source), but at least the really extreme differences should be tampered.

howardpc:
Does your hardware have an FPU, and do you know for sure it is being utilised in this exercise; or is the compiler emulating it?

DelphiFreak:
Hi,

I am not sure if your "translated" code is correct.
Because there a few things which could be optimized.

See my code.


--- Code: ---program project1;
{$mode objfpc}

uses
  windows,
  interfaces,
  sysutils;

var
  z: integer;
  _start:longint;

  function DoIt(const x: double): double;
  var
    Mu: double = 10.0;
    Su: double;
    I, J, N: integer;
  begin
    _start:=GetTickCount;
    N := 500000;
    result := 0;

    for I := 0 to N - 1 do begin
      Su := 0.0;
      for J := 0 to 99 do begin
        Mu := (Mu + 2.0) / 2.0;
        Su := x * Su + Mu;
      end;
      result := result + Su;
    end;
  end;

begin
  _start:=GetTickCount;
  for z := 1 to 10 do writeln(DoIt(0.2));
  writeln(inttostr(GetTickCount-_Start));
  readln;
end. 
--- End code ---

kamischi:
Does Gambas float really correspond to double or to single? This could make quite some difference. Actually, on 64bit it does not make a difference. With ppc386 there is one. But a real boost came from changing that one line to:
   Mu := 0.5 * Mu + 1.0;
and compile with -O3
and the time went down to below 50%.

kamischi:

--- Quote from: Blaazen on October 13, 2014, 07:49:17 pm ---Also, try replace

--- Code: ---... / 2.0;
--- End code ---
with

--- Code: ---... * 0.5;
--- End code ---
Maybe it is done automatically, I'm not sure.

--- End quote ---
It does not seem to be done.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version