[fpc-devel] performance tests: reference counted vs non-reference counted

Graeme Geldenhuys graemeg.lists at gmail.com
Fri Nov 16 12:50:00 CET 2007


On 16/11/2007, Mattias Gaertner <nc-gaertnma at netcologne.de> wrote:
>
> Why are the iteration differences that big? 566 vs 935?
> There seems to be a problem with how you test/measure.
>


Okay, I removed the 'for i := 1 to 10000' loop so that we only have a
single loop (while ...) and create objects in that loop.  Results seem
to be more consistent now and the results of the MyBaseObject  usage
has changed dramatically. They are much closer together than with the
'for' loop.  Weird that the 'for' loop would have made such a huge
difference in timing!!

Another weird observation....

  * The Delphi 7 test runs inside a VirtualBox session, which normally
I would have thought would
     make programs run slower. Even so, Delphi 7 in a VirtualBox
creates 4+ million objects more
     than FPC running in a native installed Ubuntu.  Huge difference in speed!!!

  * TInterfacedObject still beats TObject under FPC. (makes no sense)
Not Delphi though.

  * The results of TMyBaseObject with and without reference counting
is opposite between the
     two compilers.  Again, it makes no sense.


What is going on???  :-)


Example test without for loop:

procedure TMyApplication.TestRefCountedObjects;
var
  LO: TInterfacedObject;
  LStart: Cardinal;
  LCount: Cardinal;
  i: integer;
begin
  LCount := 0;
  LStart := tiGetTickCount;
  while tiGetTickCount - LStart < (CTestRunTime * 1000) do
  begin
    LO := TInterfacedObject.Create;
    Inc(LCount);
  end;
  Log(Format('%s iterations in %d seconds (reference counting)',
      [IntToStr(LCount), CTestRunTime]));
end;


**** FPC 2.2.0 under Ubuntu 7.10 (native OS)

graemeg at graemeg:Demo$ ./performancetest
1782823 iterations in 5 seconds (no reference counting with TObject)
1989364 iterations in 5 seconds (reference counting with TInterfacedObject)
1878392 iterations in 5 seconds (no reference counting with MyBaseObject)
1848856 iterations in 5 seconds (reference counting with MyBaseObject)


graemeg at graemeg:Demo$ ./performancetest
1699145 iterations in 5 seconds (no reference counting with TObject)
1923287 iterations in 5 seconds (reference counting with TInterfacedObject)
1849223 iterations in 5 seconds (no reference counting with MyBaseObject)
1836972 iterations in 5 seconds (reference counting with MyBaseObject)


graemeg at graemeg:Demo$ ./performancetest
1876295 iterations in 5 seconds (no reference counting with TObject)
1868920 iterations in 5 seconds (reference counting with TInterfacedObject)
1840136 iterations in 5 seconds (no reference counting with MyBaseObject)
1835363 iterations in 5 seconds (reference counting with MyBaseObject)



**** Delphi 7 under Win2000 (in a VirtualBox session)

C:\programming\tests\performancetest>performancetest
5782111 iterations in 5 seconds (no reference counting with TObject)
5555045 iterations in 5 seconds (reference counting with TInterfacedObject)
4301854 iterations in 5 seconds (no reference counting with MyBaseObject)
4742419 iterations in 5 seconds (reference counting with MyBaseObject)

C:\programming\tests\performancetest>performancetest
6002846 iterations in 5 seconds (no reference counting with TObject)
5679972 iterations in 5 seconds (reference counting with TInterfacedObject)
4305841 iterations in 5 seconds (no reference counting with MyBaseObject)
4829425 iterations in 5 seconds (reference counting with MyBaseObject)

C:\programming\tests\performancetest>performancetest
6007751 iterations in 5 seconds (no reference counting with TObject)
5704604 iterations in 5 seconds (reference counting with TInterfacedObject)
4301758 iterations in 5 seconds (no reference counting with MyBaseObject)
4878739 iterations in 5 seconds (reference counting with MyBaseObject)



Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-devel mailing list