How can I use the QTest::setBenchmarkResult method? I want an example of it. I have used this code:
QBENCHMARK{
// Some code here ...
}
I want to catch the result of the benchmark and with a especific metric.
How can I use the QTest::setBenchmarkResult method? I want an example of it. I have used this code:
QBENCHMARK{
// Some code here ...
}
I want to catch the result of the benchmark and with a especific metric.
Let's see example from the documentation:
void TestBenchmark::simple()
{
QString str1 = QLatin1String("This is a test string");
QString str2 = QLatin1String("This is a test string");
QCOMPARE(str1.localeAwareCompare(str2), 0);
QBENCHMARK {
str1.localeAwareCompare(str2);
}
}
Is it what you need?
How can I use the QTest::setBenchmarkResult method?
You can use it to report a benchmark-metric result-value that you calculated yourself:
class CustomTimerBenchmark : public QObject
{
Q_OBJECT
private slots:
void BenchmarkNanosecondsWithCustomTimer()
{
MyCustomTimer myCustomTimer;
timer.start();
// here goes benchmarked code
QTest::setBenchmarkResult(
myCustomTimer.nanoseconds(), QTest::WalltimeNanoseconds);
// ^^^^
// This will treat BenchmarkNanosecondsWithCustomTimer
// as benchmark that reports wall-time in nanoseconds
}
};
I want to catch the result of the benchmark and with a especific metric.
You can not do it with QTest::setBenchmarkResult