[Gambas-user] Wow, Gambas is twice as fast as (Free) Pascal

T Lee Davidson t.lee.davidson at ...626...
Sat Oct 11 18:32:47 CEST 2014


On 10/11/2014 08:52 AM, Benoît Minisini wrote:
> You're right, I thought that the number of occurrences was printed, not
> the result. Always look at the code before answering!:-)
>
> Well, as Fabien says, shows the Pascal code. I find strange that a
> compiled Pascal program is twice slower than an interpreted Gambas
> program. Or there is something weird in the Lazarus compiler?
>
> Regards,
>
> -- Benoît Minisini

I thought it was strange too, Benoît. But, at the same time, also 
thought it was highly impressive on Gambas' (and its developers') 
account. :-)


I have tried compiling the Pascal program with {$OPTIMIZATION ON} and 
also {$RANGECHECKS OFF} (even though that should be the default) with no 
improvement in performance.

Here's the Pascal code:

program Polynom;
{$mode objfpc}

var
   z : integer;

function DoIt(x : double) : double;
   var Mu : double = 10.0;
   var Pu, Su : double;
   var I, J, N : integer;
   var aPoly : array [0..99] of double;

begin
   N := 500000;
   Pu := 0;

   For I := 0 To N-1 do
   begin
     For J := 0 To 99 do
     begin
       Mu :=  (Mu + 2.0) / 2.0;
       aPoly[J] := Mu;
     end;
     Su := 0.0;
     For J := 0 To 99 do
     begin
       Su := X * Su + aPoly[J];
     end;
     Pu := Pu + Su;
   end;

   DoIt := Pu;
end;

Begin

For z := 1 To 10 do
begin
	writeln( DoIt(0.2) );
end;

End.




More information about the User mailing list