Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate gcc compilation time?

Tags:

I want to know GCC compile time. Does GCC have any command or option for calculate compile time?

I have a file named hello.c and will compile it. I want to know the time spent to compile it.

like image 366
PS.OHM Avatar asked Jun 11 '10 18:06

PS.OHM


People also ask

How do you calculate compilation time?

Hence taking the difference of starts and ends will give you execution time of test_case() in second multiplied by CLOCKS_PER_SEC . CLOCKS_PER_SEC is the number of clock ticks per second. Compile time calculation can be done using template metaprogramming.

How much time does it take to compile GCC?

You mean compiling gcc from sources? Depends on what machine you have. I don't compile gcc very often, but it would probably take about 10–15 minutes on my work-machine. At home, it would probably take somewhere between 30–60 minutes.

How long does it take to compile GCC 10?

You typically don't want to mess the system's default GCC because other packages may depend on the default version. Depending on the speed of your computer the build phase could take from about 30 minutes to a few hours.


2 Answers

To get a more comprehensive breakdown of compilation-time than what time can provide you can use -ftime-report:

g++ -s -O3 -ftime-report hello.c -o hello.exe

Execution times (seconds)
 callgraph construction:   0.01 ( 1%) usr     224 kB ( 1%) ggc
 callgraph optimization:   0.01 ( 1%) usr     147 kB ( 0%) ggc
 cfg cleanup           :   0.01 ( 1%) usr       8 kB ( 0%) ggc
 df live regs          :   0.02 ( 2%) usr       0 kB ( 0%) ggc
 df live&initialized regs:   0.01 ( 1%) usr       0 kB ( 0%) ggc
 alias analysis        :   0.01 ( 1%) usr      67 kB ( 0%) ggc
 preprocessing         :   0.08 (10%) usr    2869 kB ( 8%) ggc
 parser                :   0.31 (40%) usr   24239 kB (66%) ggc
 name lookup           :   0.06 ( 7%) usr    3086 kB ( 8%) ggc
 inline heuristics     :   0.01 ( 1%) usr      16 kB ( 0%) ggc
 integration           :   0.01 ( 1%) usr    1499 kB ( 4%) ggc
 tree gimplify         :   0.01 ( 1%) usr     422 kB ( 1%) ggc
 tree CFG cleanup      :   0.01 ( 1%) usr      12 kB ( 0%) ggc
 tree VRP              :   0.01 ( 1%) usr     146 kB ( 0%) ggc
 tree PTA              :   0.01 ( 1%) usr      66 kB ( 0%) ggc
 tree SSA rewrite      :   0.01 ( 1%) usr     159 kB ( 0%) ggc
 tree SSA incremental  :   0.01 ( 1%) usr      35 kB ( 0%) ggc
 tree operand scan     :   0.01 ( 1%) usr     628 kB ( 2%) ggc
 tree PRE              :   0.02 ( 3%) usr     101 kB ( 0%) ggc
 tree FRE              :   0.01 ( 1%) usr      25 kB ( 0%) ggc
 dominance computation :   0.01 ( 1%) usr       0 kB ( 0%) ggc
 expand                :   0.03 ( 4%) usr     528 kB ( 1%) ggc
 CSE                   :   0.01 ( 1%) usr       8 kB ( 0%) ggc
 CSE 2                 :   0.01 ( 1%) usr       6 kB ( 0%) ggc
 branch prediction     :   0.01 ( 1%) usr      67 kB ( 0%) ggc
 combiner              :   0.01 ( 1%) usr      48 kB ( 0%) ggc
 integrated RA         :   0.02 ( 2%) usr      53 kB ( 0%) ggc
 reload                :   0.01 ( 2%) usr     114 kB ( 0%) ggc
 reload CSE regs       :   0.01 ( 1%) usr      95 kB ( 0%) ggc
 final                 :   0.01 ( 1%) usr       3 kB ( 0%) ggc
 TOTAL                 :   0.79             36953 kB

This will work on any platform since you're using a switch supported by the compiler itself rather than relying on another timing program.

like image 167
greatwolf Avatar answered Sep 19 '22 10:09

greatwolf


You can use the time utility:

$ time gcc -c hello.c

real    0m0.224s
user    0m0.013s
sys     0m0.010s

Here's a link to the man page.

like image 23
Carl Norum Avatar answered Sep 22 '22 10:09

Carl Norum