This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
penalty for member functions?
- To: gcc at gcc dot gnu dot org
- Subject: penalty for member functions?
- From: Ulrich Lauther <ulrich dot lauther at mchp dot siemens dot de>
- Date: Sun, 21 Nov 1999 10:26:31 +0100 (MET)
- Reply-To: Ulrich dot Lauther at mchp dot siemens dot de
In an attempt to track down the difference between a fast C and
significantly slower C++ implementation of the same algorithm,
I wrote a small programm that loops over the elements of a linked
list and accesses some data members of another struct via pointers.
I made two versions of the loop: one as a global function, one as
a member function, and measured the cpu-time for 10**7 cycles of the
loop.
Here are the results for different optimization levels of gcc-2.95.1,
table entries are cpu-seconds:
global | member
function | function
-------------------
-O0 | 4.900 | 4.890
-O1 | 0.870 | 1.500
-O2 | 0.640 | 1.510
-O3 | 0.640 | 0.690
With -O1 and -O2, the member function is significantly slower than
the global function.
Is there a general runtime penalty for object oriented programing?
(May be due to shortage of registers?)
Operating system is Linux and here is my cpuinfo:
processor : 0
vendor_id : GenuineIntel
cpu family : 5
model : 8
model name : Mobile Pentium MMX
stepping : 1
cpu MHz : 233.868366
fdiv_bug : no
hlt_bug : no
sep_bug : no
f00f_bug : yes
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr mce cx8 mmx
bogomips : 466.94
--
-lauther
----------------------------------------------------------------------------
Ulrich Lauther ph: +49 89 636 48834 fx: ... 636 42284
Siemens ZT SE 4 Internet: Ulrich.Lauther@mchp.siemens.de