Date: Wed, 11 Feb 2009 21:43:14 GMT From: Guillaume Morin <guillaume@morinfr.org> To: freebsd-gnats-submit@FreeBSD.org Subject: misc/131597: c++ exceptions very slow on FreeBSD 7.1/amd64 Message-ID: <200902112143.n1BLhEtL083946@www.freebsd.org> Resent-Message-ID: <200902112150.n1BLo3QH044462@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 131597
>Category: misc
>Synopsis: c++ exceptions very slow on FreeBSD 7.1/amd64
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Wed Feb 11 21:50:03 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator: Guillaume Morin
>Release: 7.1-RELEASE
>Organization:
>Environment:
FreeBSD freebsd 7.1-RELEASE FreeBSD 7.1-RELEASE #0: Thu Jan 1 08:58:24 UTC 2009 root@driscoll.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64
>Description:
I have a very simple C++ program that simply throws 100,000 exceptions. Compiled on my Core 2 Duo running FreeBSD, it takes 4 secs to run. On my linux box running a 4 year old Athlon 64, it takes 0.4 secs. It looks like the FreeBSD implementation makes a *lot* of syscalls.
We found this problem while running test code for our libraries which is very exception heavy.
Here is the program:
$cat testexcept.cpp
int main(void) {
int i = 0;
while(1) {
++i;
try {
if(i == 100000) {
break;
}
throw 0;
}
catch(...) {
}
}
return 0;
}
$g++ -v
Using built-in specs.
Target: amd64-undermydesk-freebsd
Configured with: FreeBSD/amd64 system compiler
Thread model: posix
gcc version 4.2.1 20070719 [FreeBSD]
$g++ -o t testexcept.cpp
$time ./t
real 0m4.436s
user 0m4.292s
sys 0m0.144s
$truss -oout ./t
$wc -l out
1000072 out
$grep sigprocmask out | sort | uniq -c
499999 sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0)
499999 sigprocmask(SIG_SETMASK,0x0,0x0) = 0 (0x0)
Same program on the linux box
=============================
linux $g++-4.2 -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.2.4 (Debian 4.2.4-6)
linux $g++-4.2 -m64 -o t testexcept.cpp
linux $time ./t
real 0m0.421s
user 0m0.404s
sys 0m0.000s
linux $strace -oout ./t
linux $wc -l out
54 out
linux $
Both machines have a similar frequency (around 2Ghz) but the Core 2 Duo should be faster. Both boxes were very lightly loaded
>How-To-Repeat:
Compile and run the program :)
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200902112143.n1BLhEtL083946>
