<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - performance bug: libc++ std::isinf() with integer input is very slow vs libstdc++"
   href="https://bugs.llvm.org/show_bug.cgi?id=32554">32554</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>performance bug: libc++ std::isinf() with integer input is very slow vs libstdc++
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>4.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>sean@rogue-research.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18239" name="attach_18239" title="repro case">attachment 18239</a> <a href="attachment.cgi?id=18239&action=edit" title="repro case">[details]</a></span>
repro case

(filing this for a colleague that doesn't have an account here.)

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.

It seems there is a performance bug in libc++'s std::isinf().


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</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>