gpt4 book ai didi

c++ - 如何使用 QTest QBENCHMARK 宏结果作为单元测试中的参数

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:43:27 27 4
gpt4 key购买 nike

我正在使用 Qt 中的 QTest 编写一些单元测试。我还遇到了 QBENCHMARK 宏,它对其封装的代码进行基准测试。

我正在运行我的单元测试并对一些代码进行基准测试。 QBENCHMARK 报告执行某些方法所花费的时间,这很好。我想在单元测试中使用执行时间,例如 QVERIFY2()。我该怎么做?

编辑:

我目前正在做的是:

void UnitTest::benchmark()
{
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);
}
}

最佳答案

来自文档:

void QTest::setBenchmarkResult(qreal result, QBenchmarkMetric metric)

Sets the benchmark result for this test function to result.

Use this function if you want to report benchmark results without using the QBENCHMARK macro. Use metric to specify how Qt Test should interpret the results.

The context for the result will be the test function name and any data tag from the _data function. This function can only be called once in each test function, subsequent calls will replace the earlier reported results.

Note that the -iterations command line argument has no effect on test functions without the QBENCHMARK macro.

你当然也可以只使用 an elapsed timer对于这样的事情。

关于c++ - 如何使用 QTest QBENCHMARK 宏结果作为单元测试中的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24042135/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com