This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

penalty for member functions?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]