<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none"><!-- P { margin-top: 0px; margin-bottom: 0px; }--></style>
</head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<div>Hi,<br>
</div>
<div><br>
</div>
<div>While writing a templated function for both floating point and integral types, I noticed that std::isinf with integer input is slow. <span style="font-size: 12pt;">I red</span><span style="font-size: 12pt;">uced 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++, u</span><span style="font-size: 12pt;">sing tag dispatch to fir</span><span style="font-size: 12pt;">st</span><span style="font-size: 12pt;"> c</span><span style="font-size: 12pt;">heck </span><span style="font-size: 12pt;">if
 the type has infinit</span><font size="3">y speeds up the calculation by several times. With </font>either compiler and <font size="3">libstdc++,  timings in both cases are fast and nearly identical. </font></div>
<div><br>
</div>
<div>Is there a performance bug in libc++'s std::isinf?</div>
<div><br>
</div>
<div>Best,</div>
<div>Steven<br>
<br>
</div>
<div>macOS 10.11 w/ clang 4.0.0 from homebrew<br>
</div>
$ /usr/local/opt/llvm/bin/clang++ -O3 -std=c++1z isinf_libcxx.cpp <br>
$ ./a.out <br>
Using Detail::isinf<br>
Time (s): 0.184412<br>
Standard Deviation: 0.0100509<br>
Using std::isinf<br>
Time (s): 0.579823<br>
Standard Deviation: 0.0205093<br>
<br>
<span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">macOS 10.11 w/ gcc 6.3.0 from home</span><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">brew</span><br>
$ g++-6 -O3 -std=c++1z <span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">isinf_libcxx</span>​.cpp<br>
$ ./a.out <br>
Using Detail::isinf<br>
Time (s): 0.195277<br>
Standard Deviation: 0.016476<br>
Using std::isinf<br>
Time (s): 0.196114<br>
Standard Deviation: 0.0161064
<div><br>
</div>
<div>Fedora 25 w/ clang 3.9.1<br>
</div>
<div>$ clang++ -O3 -std=c++1z -stdlib=libc++ <span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
isinf_libcxx</span>.cpp<br>
$ ./a.out <br>
Using Detail::isinf<br>
Time (s): 0.161073<br>
Standard Deviation: 0.00445347<br>
Using std::isinf<br>
Time (s): 1.40411<br>
Standard Deviation: 0.089235</div>
<div><br>
</div>
<div><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">Fedora 25 w/ clang 3.9.1</span><br>
$ clang++ -O3 -std=c++1z -stdlib=libstdc++ <span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">
isinf_libcxx</span>.cpp<br>
$ ./a.out <br>
Using Detail::isinf<br>
Time (s): 0.162251<br>
Standard Deviation: 0.00350547<br>
Using std::isinf<br>
Time (s): 0.160011<br>
Standard Deviation: 0.00220987<br>
<p><br>
</p>
</div>
</body>
</html>