Slow performance of libc++ std::isinf with integral types

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Slow performance of libc++ std::isinf with integral types

Richard Pennington via cfe-dev
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



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

isinf_libcxx.cpp (4K) Download Attachment
Loading...