I am writing a pthread code in C, and using gcc compiler. I have implemented a code with pthread_condition, mutex locks and semaphores.. Is there any flag or option in gcc to enhance the execution time?
Program is written to solve this Problem
I am writing a pthread code in C, and using gcc compiler. I have implemented a code with pthread_condition, mutex locks and semaphores.. Is there any flag or option in gcc to enhance the execution time?
Program is written to solve this Problem
the gcc
manpage reveals:
-O
-O1 Optimize.
Optimizing compilation takes somewhat more time, and a lot more
memory for a large function. With -O, the compiler tries to reduce
code size and execution time, without performing any optimizations
that take a great deal of compilation time.
-O2 Optimize even more.
GCC performs nearly all supported optimizations that do not involve a
space-speed tradeoff. As compared to -O, this option increases both
compilation time and the performance of the generated code.
-O3 Optimize yet more.
-O3 turns on all optimizations specified by -O2 and also turns on the
-finline-functions, -funswitch-loops, -fpredictive-commoning,
-fgcse-after-reload, -ftree-vectorize and -fipa-cp-clone options.
so if you want your code to run faster ("minimize execution time"), a good start is to use -O3
.
since the optimizations will be generic, you will have to do a lot of benchmarking to get best results for a given code.