Is there a method to measure the time taken by the Preprocessor to make its steps? Or is this just straightforward, counting lines of code (more lines of code -> more time taken for preprocessing)?
1 Answer
From Custom gcc preprocessor and using time you can write the following wrapper around cc1:
#!/bin/sh echo "cc1 $*" >&2 time $(${COLLECT_GCC} --print-prog-name=cc1) "$@" The wrapper outputs cc1 commmand with arguments and the time it taken:
$ gcc -no-integrated-cpp -B$PWD 1.c cc1 -E -quiet 1.c -mtune=generic -march=x86-64 -o /tmp/cckqYvRJ.i real 0m0.014s user 0m0.009s sys 0m0.005s cc1 -fpreprocessed /tmp/cckqYvRJ.i -quiet -dumpdir a- -dumpbase 1.c -dumpbase-ext .c -mtune=generic -march=x86-64 -o /tmp/ccePvbYm.s real 0m0.021s user 0m0.015s sys 0m0.006s The time below cc1 -E .. is the time taken by the preprocessor.
If you are referring to measuring time taken by each of the translation phases separately, then no, it is not possible. The phases are not done "separately" - all of them, at once, intermixed, are done by one program. The end result is "as-if" the phases would be done one after the other. From the link, emphasis mine:
The C source file is processed by the compiler as if the following phases take place, in this exact order. Actual implementation may combine these actions or process them differently as long as the behavior is the same.
time gcc -E source.cit's roughly enough to give you an idea.