0

如何使用 QTest::setBenchmarkResult 方法?我想要一个例子。我用过这段代码:

QBENCHMARK{
    // Some code here ...
}

我想用一个特定的指标来捕捉基准测试的结果。

4

2 回答 2

0

让我们看一下文档中的示例:

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);
    }
}

这是你需要的吗?

于 2014-09-30T05:57:52.803 回答
0

如何使用 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

于 2017-04-28T09:29:14.970 回答