0

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)?

5
  • Are you asking this in terms of "the fraction of compile time taken by the preprocessor"? May I ask why you need to know? Commented Jul 16, 2013 at 15:07
  • 1
    time gcc -E source.c it's roughly enough to give you an idea. Commented Jul 16, 2013 at 15:08
  • @Floris I think i mean just the first 4 steps in translation phase. I want to know how to use structures effictively. Commented Jul 16, 2013 at 15:35
  • @user2485710 Thanks, that worked. But the values are somehow volatile - differences up to 100% for sys. The time function seems to apply to some other processes, which I can't really specify so far. Commented Jul 16, 2013 at 15:42
  • 2
    "I want to know how to use structures effictively". Not by measuring preprocessing times, that's for sure. Commented Jul 6, 2016 at 21:15

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.