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

Graeme Geldenhuys graemeg.lists at gmail.com
Fri Nov 16 13:21:32 CET 2007


On 16/11/2007, Mattias Gaertner <nc-gaertnma at netcologne.de> wrote:
> I tested your tests and the results were completely random.
> - They need so much memory that the OS page handling interferes.
> - You used the slow 'Now' function.

Okay, to eliminate both those, I changed the loop again. You were
right about the OS page handling by the way. I heard the HDD page in
some tests.

Test notes:
--------------------
- I free both Non-Ref. and Ref. counted objects.
- I now loop 1mil times and check the time taken.
- Now() gets called once before the loop and once after the loop to
get the time taken.


As you can see the reference counted TInterfacedObject always seem to
beat the non-ref. counted TObject.  The use of MyBaseObject, yet again
yields a predictable (what you would expect) and constant result.


graemeg at graemeg:Demo_TtiBaseObject$ ./performancetest
1000000 iterations in 302 ms (no reference counting with TObject)
1000000 iterations in 247 ms (reference counting with TInterfacedObject)
1000000 iterations in 260 ms (no reference counting with MyBaseObject)
1000000 iterations in 336 ms (reference counting with MyBaseObject)

graemeg at graemeg:Demo_TtiBaseObject$ ./performancetest
1000000 iterations in 316 ms (no reference counting with TObject)
1000000 iterations in 236 ms (reference counting with TInterfacedObject)
1000000 iterations in 253 ms (no reference counting with MyBaseObject)
1000000 iterations in 324 ms (reference counting with MyBaseObject)

graemeg at graemeg:Demo_TtiBaseObject$ ./performancetest
1000000 iterations in 304 ms (no reference counting with TObject)
1000000 iterations in 245 ms (reference counting with TInterfacedObject)
1000000 iterations in 268 ms (no reference counting with MyBaseObject)
1000000 iterations in 317 ms (reference counting with MyBaseObject)


Example of test loop now.


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



Any idea why Delphi in a virtualbox still beats FPC?  Delphi seems
considerably faster and it's in a virtual machine.  Oh, and I'm using
a stock standard single core Intel P4 CPU 2.40GHz and it hasn't got
any special virtualization features built in.
Also not, that Delphi now yields a constant result. Reference counted
classes are always slower.


C:\programming\tests\performancetest>performancetest
1000000 iterations in 181 ms (no reference counting with TObject)
1000000 iterations in 250 ms (reference counting with TInterfacedObject)
1000000 iterations in 221 ms (no reference counting with MyBaseObject)
1000000 iterations in 300 ms (reference counting with MyBaseObject)

C:\programming\tests\performancetest>performancetest
1000000 iterations in 180 ms (no reference counting with TObject)
1000000 iterations in 251 ms (reference counting with TInterfacedObject)
1000000 iterations in 229 ms (no reference counting with MyBaseObject)
1000000 iterations in 270 ms (reference counting with MyBaseObject)

C:\programming\tests\performancetest>performancetest
1000000 iterations in 189 ms (no reference counting with TObject)
1000000 iterations in 241 ms (reference counting with TInterfacedObject)
1000000 iterations in 210 ms (no reference counting with MyBaseObject)
1000000 iterations in 269 ms (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