💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[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); } } } ```