[cfe-dev] Slow performance of libc++ std::isinf with integral types

Hahn, Steven E. via cfe-dev cfe-dev at lists.llvm.org
Thu Mar 23 18:32:29 PDT 2017


Hi,

While writing a templated function for both floating point and integral types, I noticed that std::isinf with integer input is slow. I reduced the code to the attached benchmark and ran it on macOS 10.11 and Fedora 25 with both clang and GCC. With clang and libc++, using tag dispatch to first check if the type has infinity speeds up the calculation by several times. With either compiler and libstdc++,  timings in both cases are fast and nearly identical.

Is there a performance bug in libc++'s std::isinf?

Best,
Steven

macOS 10.11 w/ clang 4.0.0 from homebrew
$ /usr/local/opt/llvm/bin/clang++ -O3 -std=c++1z isinf_libcxx.cpp
$ ./a.out
Using Detail::isinf
Time (s): 0.184412
Standard Deviation: 0.0100509
Using std::isinf
Time (s): 0.579823
Standard Deviation: 0.0205093

macOS 10.11 w/ gcc 6.3.0 from homebrew
$ g++-6 -O3 -std=c++1z isinf_libcxx?.cpp
$ ./a.out
Using Detail::isinf
Time (s): 0.195277
Standard Deviation: 0.016476
Using std::isinf
Time (s): 0.196114
Standard Deviation: 0.0161064

Fedora 25 w/ clang 3.9.1
$ clang++ -O3 -std=c++1z -stdlib=libc++ isinf_libcxx.cpp
$ ./a.out
Using Detail::isinf
Time (s): 0.161073
Standard Deviation: 0.00445347
Using std::isinf
Time (s): 1.40411
Standard Deviation: 0.089235

Fedora 25 w/ clang 3.9.1
$ clang++ -O3 -std=c++1z -stdlib=libstdc++ isinf_libcxx.cpp
$ ./a.out
Using Detail::isinf
Time (s): 0.162251
Standard Deviation: 0.00350547
Using std::isinf
Time (s): 0.160011
Standard Deviation: 0.00220987

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170324/618a58f2/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: isinf_libcxx.cpp
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170324/618a58f2/attachment.ksh>


More information about the cfe-dev mailing list