【发布时间】:2012-10-23 03:41:42
【问题描述】:
我在 Windows 上使用 QtCreator,我想知道如何让我的编译器优化输出。
我的理解是MinGW是GCC的一个端口。所以,我应该能够使用诸如 -O2 之类的参数。但是,在“项目”栏中,我看到的唯一内容是:
- qmake 的构建步骤(可能不在此处,qmake 是关于 .pro 文件/MOC/Qt 的东西...)
- mingw32-make 的构建步骤(可能)
- 清理步骤(可能不是)
所以,我尝试在“Make arguments”框中添加 -O2,但不幸的是,我收到错误“invalid option --O”
对于任何感兴趣的人,我正在尝试实现the Ackermann function,因为我读到了:
阿克曼函数,由于它的定义是极 深度递归,可用作编译器能力的基准 优化递归
代码(并没有真正使用 Qt):
#include <QtCore/QCoreApplication>
#include <QDebug>
#include <ctime>
using namespace std;
int nbRecursion;
int nbRecursions9;
int Ackermann(int m, int n){
nbRecursion++;
if(nbRecursion % 1000000 == 0){
qDebug() << nbRecursions9 << nbRecursion;
}
if(nbRecursion == 1000000000){
nbRecursion = 0;
nbRecursions9++;
}
if(m==0){
return n+1;
}
if(m>0 && n>0){
return Ackermann(m-1,Ackermann(m, n-1));
}
if(m>0 && n==0){
return Ackermann(m-1,1);
}
qDebug() << "Bug at " << m << ", " << n;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
nbRecursion = 0;
nbRecursions9 = 0;
int m = 3;
int n = 13;
clock_t begin = clock();
Ackermann(m,n);
clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
qDebug() << "There are " << CLOCKS_PER_SEC << " CLOCKS_PER_SEC";
qDebug() << "There were " << nbRecursions9 << nbRecursion << " recursions in " << elapsed_secs << " seconds";
double timeX = 1000000000.0*((elapsed_secs)/(double)nbRecursion);
if(nbRecursions9>0){
timeX += elapsed_secs/(double)nbRecursions9;
}
qDebug() << "Time for a function call : " << timeX << " nanoseconds";
return a.exec();
}
【问题讨论】:
标签: optimization mingw qt-creator