#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
quint64 count = 30;
QStringList results;
const QString templateStr = QString("a = %1; b = %2; c = %3");
QString tmp;
for (int i=0; i < 5; i++){
QTime testTime; testTime.start();
for (int a = 0, b = 0, c = 0; a < count; c++, b+=(c<count?0:(c=0,1)), a+=(b<count?0:(b=0,1))){
tmp = templateStr.arg(a).arg(b).arg(c);
}
qDebug() << QString("iter %1: first loop - job is done").arg(i);
quint64 result1 = testTime.elapsed();
testTime.restart();
for (int a = 0; a < count; a++){
for (int b = 0; b < count; b++){
for (int c = 0; c < count; c++){
tmp = templateStr.arg(a).arg(b).arg(c);
}
}
}
qDebug() << QString("iter %1: second loop - job is done").arg(i);
quint64 result2 = testTime.elapsed();
results.append(QString("result1 = %1; result2 = %2; result 1 < result2 = %3").arg(result1).arg(result2).arg(result1 < result2?"true":"false"));
}
for (QString resString : results){
qDebug() << resString;
}
return app.exec();
}
"iter 0: first loop - job is done"
"iter 0: second loop - job is done"
"iter 1: first loop - job is done"
"iter 1: second loop - job is done"
"iter 2: first loop - job is done"
"iter 2: second loop - job is done"
"iter 3: first loop - job is done"
"iter 3: second loop - job is done"
"iter 4: first loop - job is done"
"iter 4: second loop - job is done"
"result1 = 20; result2 = 21; result 1 < result2 = true"
"result1 = 22; result2 = 21; result 1 < result2 = false"
"result1 = 21; result2 = 20; result 1 < result2 = false"
"result1 = 19; result2 = 22; result 1 < result2 = true"
"result1 = 20; result2 = 22; result 1 < result2 = true"
for (int a = 0, b = 0, c = 0; a < count; c++, b+=(c<count?0:(c=0,1)), a+=(b<count?0:(b=0,1))){
qDebug() << QString("a = %1; b = %2; c = %3").arg(a).arg(b).arg(c);
}