测试条件:
- Windows7 PC;
- 编译器MSVC2010;
- QT5.5.1;
- 计数接口API:QueryPerformanceCounter();
- 节点量 100个;
用来做测试的数据xml 和 ini文本
测试实验目标
- 分别一次性读出ini 和 xml 中的 键值对数据;
读XML方法
QString filepath = “d:\usefile.xml”;
QFileInfo fileinfo(filepath);
if (!fileinfo.exists())
return;
QFile file(filepath);
if (!file.open(QIODevice::ReadWrite)) {
return;
}
QDomDocument doc;
if (!doc.setContent(&file)) {
file.close();
return;
}
file.close();
QDir dir(fileinfo.path());
QDomNodeList nodes = doc.documentElement().elementsByTagName("item");
qDebug() << "nodes.length()___" << nodes.length();
if (nodes.length() < 1)
return;
QDomElement element;
//CT t;
LARGE_INTEGER Freq;
LARGE_INTEGER BeginTime;
LARGE_INTEGER EndTime;
int res;
QueryPerformanceFrequency(&Freq); // 获取时钟周期
QueryPerformanceCounter(&BeginTime); // 获取时钟计数
for (int i = 0; i < nodes.size(); i++) {
QDomNode node = nodes.at(i);
element = node.toElement();
QList<QStandardItem*> item;
QString id = element.attribute("src");
QString name = element.attribute("dst");
}
//t.Print();
QueryPerformanceCounter(&EndTime);
//printf("kinematicsForward = %d %lf us\n", res, 1000000.0 * (EndTime.QuadPart-BeginTime.QuadPart)/Freq.QuadPart);
qDebug() << QString("[XML]: kinematicsForward = %1 %2 us").arg(QString::number(res)).arg(QString::number(1000000.0 * (EndTime.QuadPart-BeginTime.QuadPart)/Freq.QuadPart));
qDebug() << nodes.size();
读ini 的方法
QString filePath = “d:\usefile.ini”;
LPWSTR strStudName;
QString key, var;
//CT t;
LARGE_INTEGER Freq;
LARGE_INTEGER BeginTime;
LARGE_INTEGER EndTime;
int res;
QueryPerformanceFrequency(&Freq); // 获取时钟周期
QueryPerformanceCounter(&BeginTime); // 获取时钟计数
for(int i=0; i<100; i++) {
key = QString("Count-%1").arg(i);
::GetPrivateProfileString(QString("FileCount").toStdWString().c_str(), key.toStdWString().c_str(), QString("默认姓名").toStdWString().c_str(),
strStudName,MAX_PATH,
filePath.toStdWString().c_str());
var = QString::fromStdWString(strStudName);
//qDebug() << var;
}
//t.Print();
QueryPerformanceCounter(&EndTime);
//printf("kinematicsForward = %d %lf us\n", res, 1000000.0 * (EndTime.QuadPart-BeginTime.QuadPart)/Freq.QuadPart);
qDebug() << QString("[INI]: kinematicsForward = %1 %2 us").arg(QString::number(res)).arg(QString::number(1000000.0 * (EndTime.QuadPart-BeginTime.QuadPart)/Freq.QuadPart));
实验测试结果
图1
- 在QT中读XML 要比 INI 文件更高效!
- xml 的时间为 : 51.9399 us;
- ini的时间为 : 14211.6 us