<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - Preprocessing and compiling C++ code in separate steps may be noticeably faster than normal compilation."
   href="https://llvm.org/bugs/show_bug.cgi?id=27012">27012</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Preprocessing and compiling C++ code in separate steps may be noticeably faster than normal compilation.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.8
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </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>Frontend
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>officesamurai@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=16063" name="attach_16063" title="test code">attachment 16063</a> <a href="attachment.cgi?id=16063&action=edit" title="test code">[details]</a></span>
test code

For certain source files preprocessing and compiling them separately is faster
than normal compilation. The attached "clang_speed_test2.cpp" is one of such
files (needs boost to compile).

To reproduce the issue run the following script (assumes that boost 1.60 was
unpacked to ~/Downloads):
#!/bin/bash

COMP=clang++-3.8
OPT=-std=c++14\ -stdlib=libc++\ -isystem\ $HOME/Downloads/boost_1_60_0
FILE_NAME=clang_speed_test2.cpp

time $COMP $OPT -c $FILE_NAME -o out.cpp.1.o
time $COMP $OPT -E $FILE_NAME -o out.cpp.i
time $COMP $OPT -x c++ -c out.cpp.i -o out.cpp.2.o

Sample output on my Linux laptop:
real 0m59.743s
user 0m58.788s
sys  0m0.874s

real 0m0.204s
user 0m0.176s
sys  0m0.027s

real 0m46.988s
user 0m46.124s
sys  0m0.803s

So, it looks like there is an optimization opportunity hiding inside clang. It
would be nice to have the smaller compilation time without the need of
additional workarounds.

Some notes:
1) similar results may be obtained with clang 3.6 and 3.7; as of boost - the
issue is still reproducible with 1.58, but not with 1.57 (at least for the
attached code)
2) the difference on (some of) real production code was even bigger - the
separate steps were roughly 2x faster.
3) using the "-save-temps" option eliminates the difference (but it's not an
ideal workaround since sometimes it just increases compilation time)</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>