Can you do the same test with lazarus? I did it (the same application
compiles without a change, but my results are not good on my pc. Maybe
the code must be optimized.

Start Lazarus silly benchmark
Int arithmetic elapsed time: 8437 ms with max of 1000000000
i: 1000000001
 intResult: 1
Double arithmetic elapsed time: 12578 ms with min of 10000000000, max
of 11000000000
i: 11000000000
 doubleResult: 10011632717,52295
Long arithmetic elapsed time: 16625 ms with min of 10000000000, max of
11000000000
i: 11000000000
 longResult: -672337204
Trig elapsed time: 3250 ms with max of 10000000
i: 10000000
sine: 0,420547793190771
cosine: -0,907270386181745
tangent: -0,463530827850173
logarithm: 7
 squareRoot: 3162,277660168379
IO elapsed time: 3891 ms with max of 1000000
i: 1000000
 myLine: 
abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890abcdefgh
Total Lazarus benchmark time: 44781 ms
End Lazarus benchmark

You find in attachment my project file. I also have the exe (stripped
463K) but can't send it. Lazarus/FPC are home made on 2006june08 from
svn version available at compile time (in begining of afternoon).

Regards.

2006/6/12, Lord ZealoN <[EMAIL PROTECTED]>:
Read the last line:

Update: Delphi version of the benchmark here (
http://www.dellapasqua.com/delphibench.txt )

2006/6/12, Michael Van Canneyt <[EMAIL PROTECTED]>:
>
>
> On Mon, 12 Jun 2006, Graeme Geldenhuys wrote:
>
> > Have a look at the following...
> >
> > http://www.osnews.com/story.php?news_id=5602
> > Nine Language Performance Round-up: Benchmarking Math & File I/O
> >
> > It compares C#, C, C++, VB, etc...
> > I ported the benchmark to Delphi (not tested under FPC but should be
> > interresting) a coulpe of months back. Unfortunatily, my findings are
> > not on this PC, but rather on my laptop at home.
> > If memory serves me correctly, C++ and Delphi was very close together,
> > but Delphi was slightly faster.  The port was really easy and quick to
> > do.  I attached the original code.  I will try and find my Delphi code
> > and findings and post them as well.
>
> I would be interested in seeing this :-)
>
> Michael.
>
>
_________________________________________________________________
>      To unsubscribe: mail [EMAIL PROTECTED] with
>                 "unsubscribe" as the Subject
>    archives at
http://www.lazarus.freepascal.org/mailarchives
>




--

::Mi blog::
http://blog.lordzealon.com


--
Alexandre Leclerc
program lazarusbenchv2;

{$mode objfpc}{$H+}

{ $APPTYPE CONSOLE}

uses
  SysUtils,
  classes,
  Windows,
  Math;

type
  TBenchMarkLazarus = class
  private
    startTime: Integer;
    stopTime: Integer;
    elapsedTime: Integer;
    function intArithmetic(const IntMax: Integer): Int64;
    function doubleArithmetic(const doubleMin, doubleMax: Double): Int64;
    function longArithmetic(const longMin, longMax: comp): Int64;
    function trig(const trigMax: double): Int64;
    function io(const ioMax: Integer): Int64;
    procedure Run;
  end;

function TBenchMarkLazarus.intArithmetic(const IntMax: Integer): Int64;
var
  intResult: Integer;
  i: Integer;
begin
  startTime := GetTickCount;
  intResult := 1;
  i := 1;

  while (i < intMax) do begin
    inc(i);
    dec(intResult, i);
    inc(i);
    inc(intResult, i);
    inc(i);
    intResult := intResult * i;
    inc(i);
    intResult := intResult div i;
  end;

  stopTime := GetTickCount;
  elapsedTime := stopTime - startTime;

  Writeln('Int arithmetic elapsed time: ' + IntToStr(elapsedTime) +
    ' ms with max of ' + IntToStr(intMax));
  Writeln(' i: ' + IntToStr(i));
  Writeln(' intResult: ' + IntToStr(intResult));
  Result := Int64(elapsedTime);
end;

function TBenchMarkLazarus.doubleArithmetic(const doubleMin, doubleMax: 
Double): Int64;
var
  doubleResult: double;
  i: double;
begin
  startTime := GetTickCount;
  doubleResult := doubleMin;
  i := doubleMin;

  while (i < doubleMax) do begin

    i := i + 1;
    doubleResult := doubleResult - i;
    i := i + 1;
    doubleResult := doubleResult + i;
    i := i + 1;
    doubleResult := doubleResult * i;
    i := i + 1;
    doubleResult := doubleResult / i;

  end;

  stopTime := GetTickCount;
  elapsedTime := stopTime - startTime;

  Writeln('Double arithmetic elapsed time: ' + IntToStr(elapsedTime) +
    ' ms with min of ' + FloatToStr(doubleMin) + ', max of ' + 
FloatToStr(doubleMax));
  Writeln(' i: ' + FloatToStr(i));
  Writeln(' doubleResult: ' + FloatToStr(doubleResult));
Result:=Int64(elapsedTime);end;

function TBenchMarkLazarus.longArithmetic(const longMin, longMax: comp): Int64;
var
  longResult: comp;
  i: comp;
begin
  startTime := GetTickCount;
  longResult := longMin;
  i := longMin;
  Set8087CW($133F);
  while (i < longMax) do begin

    i := i + 1;
    longResult := longResult - i;
    i := i + 1;
    longResult := longResult + i;
    i := i + 1;
    longResult := longResult * i;
    i := i + 1;
    longResult := longResult / i;

  end;

  stopTime := GetTickCount;
  elapsedTime := stopTime - startTime;

  Writeln('Long arithmetic elapsed time: ' + IntToStr(elapsedTime) +
    ' ms with min of ' + FloatToStr(longMin) + ', max of ' + 
FloatToStr(longMax));
  Writeln(' i: ' + FloatToStr(i));
  Writeln(' longResult: ' + FloatToStr(longResult));
  Result := Int64(elapsedTime);
end;

function TBenchMarkLazarus.trig(const trigMax: double): Int64;
var
  sine, cosine, tangent, logarithm, squareRoot, i: double;
begin
  startTime := GetTickCount;
  sine := 0;
  cosine := 0;
  tangent := 0;
  logarithm := 0;
  squareRoot := 0;
  i := 0;

  while (i < trigMax) do begin
    i := i + 1;
    sine := Sin(i);
    cosine := Cos(i);
    tangent := Tan(i);
    logarithm := Log10(i);
    squareRoot := Sqrt(i);
  end;

  stopTime := GetTickCount;
  elapsedTime := stopTime - startTime;


  Writeln('Trig elapsed time: ' + IntTostr(elapsedTime) +
    ' ms with max of ' + FloatToStr(trigMax));
  Writeln(' i: ' + FloatToStr(i));
  Writeln(' sine: ' + FloatToStr(sine));
  Writeln(' cosine: ' + FloatToStr(cosine));
  Writeln(' tangent: ' + FloatToStr(tangent));
  Writeln(' logarithm: ' + FloatToStr(logarithm));
  Writeln(' squareRoot: ' + FloatToStr(squareRoot));
  Result := Int64(elapsedTime);
end;

function TBenchMarkLazarus.io(const ioMax: Integer): Int64;
const 
textLine='abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890abcdefgh';
var
  myLine: string;
  i: integer;
  F: textfile;
begin
  startTime := GetTickCount;
  i := 0;

  try

    AssignFile(F, 'c:\TestLazarus.txt');
    Rewrite(F);

    while (i < ioMax) do begin
      Writeln(F, textLine);
      Inc(i);
    end;
    CloseFile(F);

    i := 0;

    AssignFile(F, 'c:\TestLazarus.txt');
    Reset(F);

    while (i < ioMax) do begin
      Readln(F, myLine);
      inc(i);
    end;

    CloseFile(F);

  except
    on e: exception do Writeln(e.Message);
  end;

  stopTime := GetTickCount;
  elapsedTime := stopTime - startTime;

  Writeln('IO elapsed time: ' + IntToStr(elapsedTime) +
    ' ms with max of ' + IntToStr(ioMax));
  Writeln(' i: ' + IntToStr(i));
  Writeln(' myLine: ' + myLine);
  Result := Int64(elapsedTime);
end;

procedure TBenchMarkLazarus.Run;
var
  intArTime, doubleArTime, longArTime, trigTime, ioTime, totalTime: Int64;
begin
  Writeln('Start Lazarus silly benchmark');

  intArTime := intArithmetic(1000000000);
  doubleArTime := doubleArithmetic(10000000000, 11000000000);
  longArTime := longArithmetic(10000000000, 11000000000);
  trigTime := trig(10000000);
  ioTime := io(1000000);
  totalTime := intArTime + doubleArTime + longArTime + trigTime + ioTime;

  Writeln('Total Lazarus benchmark time: ' + IntToStr(totalTime) + ' ms');
  Writeln('End Lazarus benchmark');
end;

var MyBench: TBenchMarkLazarus;

begin
  MyBench := TBenchMarkLazarus.Create;
  MyBench.Run;
  MyBench.Free;
end.

Reply via email to