1、 QString append追加方式,和使用QTextStream追加方式的性能比较,从下面代码可以看到在1000W次循环下,append方式耗时是QTextStream方式的3倍多,且数据量从1000次循环到1000W次循环也是这个差距比。
2、 QString arg格式化参数方式和asprintf方格式化方式耗时差不多,但是asprintf没有arg好用,且不符合QT的风格,可以弃用。
#include <QCoreApplication>
#include <QDebug>
#include <chrono>
#include <thread>
#include <QTextStream>
using namespace std::chrono;
void testappend()
{
time_point<steady_clock> start = steady_clock::now();
{
QString string;
for (int i = 0; i < 10000; i++) {
for (int j = 0; j < 1000; j++) {
string.append("i");
}
string.append("j");
}
}
tim