[OT] exception performance cost
Matthias Weiss
matthias.weiss@inode.at
Thu Apr 18 11:46:00 GMT 2002
Hi all!
This is possibly OT, please tell me if discussion of
this is unwanted on this list.
I wanted some raw number telling me the performance difference
between a C++ code with exceptions and one with error return
code.
I wrote 3 very simple C++ programs to test it. I compiled it
with different flags and first checked the size differenz.
Using exceptions increase the file size with an amount of
6 - 10 %.
Then I checked execution time. I compiled all 3 programs with
g++-3.0 -Wall -Os -O2 -fomit-frame-pointer -march=i686 -o exception_performance3 exception_performance3.cpp
and stripped them afterwards.
I ran all 3 programs at least 5 consecutive times and calculated the average.
I used the "time" comand to measure the execution time.
The result was that using exceptions introduces less than 2 % performance loss.
Then I altered the 3 files and included 2 gettimeofday calls to measure the
ellapsed time. Surprisingly the situation flipped and now not using exceptions
costs ~3 % performance.
Has anyone an explanation for this?
I have attached the 3 source files.
matthias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: exception_performance1.cpp
Type: text/x-c++src
Size: 793 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20020418/94431382/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: exception_performance2.cpp
Type: text/x-c++src
Size: 794 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20020418/94431382/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: exception_performance3.cpp
Type: text/x-c++src
Size: 724 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20020418/94431382/attachment-0002.bin>
More information about the Libstdc++
mailing list