gcc编译器中是否有用于pthread代码的标志以最小化执行时间?

时间:2013-09-18 10:46:01

标签: c multithreading gcc pthreads

我在C中编写pthread代码,并使用gcc编译器。我用pthread_condition,互斥锁和信号量实现了一个代码。在gcc中是否有任何标志或选项来增强执行时间?

编写程序是为了解决这个Problem

1 个答案:

答案 0 :(得分:3)

gcc联机帮助页显示:

   -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.

所以如果你希望你的代码运行得更快(“最小化执行时间”),一个好的开始是使用-O3

由于优化是通用的,因此您必须进行大量基准测试才能获得给定代码的最佳结果。