如何使用 QTest::setBenchmarkResult 方法?我想要一个例子。我用过这段代码:
QBENCHMARK{
// Some code here ...
}
我想用一个特定的指标来捕捉基准测试的结果。
让我们看一下文档中的示例:
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);
}
}
这是你需要的吗?
如何使用 QTest::setBenchmarkResult 方法?
您可以使用它来报告您自己计算的基准指标结果值:
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
}
};
我想用一个特定的指标来捕捉基准测试的结果。
你不能这样做QTest::setBenchmarkResult