ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ## 概述 ### 编写一个基准测试函数 ``` 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); } } ``` ### 多数据输入的基准测试 ``` void TestBenchmark::multiple_data() { QTest::addColumn<bool>("useLocaleCompare"); QTest::newRow("locale aware compare") << true; QTest::newRow("standard compare") << false; } void TestBenchmark::multiple() { QFETCH(bool, useLocaleCompare); QString str1 = QLatin1String("This is a test string"); QString str2 = QLatin1String("This is a test string"); int result; if (useLocaleCompare) { QBENCHMARK { result = str1.localeAwareCompare(str2); } } else { QBENCHMARK { result = (str1 == str2); } } } ```