Performance of method calls

Daniel Keep daniel.keep+lists at gmail.com
Wed Nov 29 22:52:00 PST 2006


Hi.

I'm currently working on a research project as part of my Honours, and 
one of the requirements is speed--the code I'm writing has to be very 
efficient.

Before I started, my supervisor warned me about object-oriented 
programming and that it seems to be much slower than just flat function 
calls.

Anyway, I was wondering what the difference between three kinds of 
function calls would be:

1. Foo x; x.call(); // Where Foo is a struct
2. Foo_call(x); // C-style API
3. auto y = new FooClass; y.call(); // Where call is final

I hooked up a test app which used a loop with 100,000 iterations for 
each call type, and ran that program 100 times, and averaged the outputs.

#1 was 2.84 times slower than #2, and #3 was 3.15 times slower than #2. 
  Are those numbers right??  Is it really that much slower?  I would 
have thought that they should have been about the same since each one 
needs to pass only one thing: a pointer.  I've attached the test 
programs I used; if anyone can offer any insight or even corrections, 
I'd be very grateful.

Incidentally, any other insights regarding performance differences 
between OO-style and flat procedural-style would be very welcome.

	-- Daniel
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: perf.sh
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20061130/927b994c/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: struct_calls.d
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20061130/927b994c/attachment-0001.ksh>


More information about the Digitalmars-d mailing list