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

标签 c multithreading gcc pthreads

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

编写程序来解决这个问题 Problem

最佳答案

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

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

关于c - gcc 编译器中是否有用于 pthread 代码的标志以最小化执行时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18870139/

相关文章:

c - 对近 80 个或更多客户端使用 select 或多线程?

c# - STAThread 属性是要求还是建议?

java - 如何打印A类中的m2方法

multithreading - bash中的简单后台进程问题

macos - GDB 7.6 STL pretty-print 与 gcc-4.8 和 mac os 10.9

c - 即使使用 %2d,输出数字也粘在一起

C++ : int _b(di*3) convert to C

c++ - 使用模板基类中的常量

gcc - 使用 GCC(内联汇编程序)将双倍加载到 FPU

c - 巨大的映射文件上的 strstr