blob: 17dc7f3f8a6df05bf4f33d93bc46bb0dd7befbe7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#include <QTest>
#include <QtXml>
#include <QmlComponent>
class tst_qmlxmlparser : public QObject
{
Q_OBJECT
public:
enum XmlParser { ParserQXmlStreamReader = 0, ParserQmlComponent };
private slots:
void parse();
void parse_data();
private:
QString readFile(QString const&);
};
/*
Benchmark the parsing of Qml, using QXmlStreamReader as a baseline.
This gives an idea of the overhead Qml imposes over the top of plain XML parsing.
*/
void tst_qmlxmlparser::parse()
{
QFETCH(QString, xml);
QFETCH(int, parser);
if (parser == ParserQXmlStreamReader) {
QBENCHMARK {
QXmlStreamReader parser(xml);
while (!parser.atEnd()) parser.readNext();
}
}
else if (parser == ParserQmlComponent) {
QByteArray ba = xml.toLatin1();
QBENCHMARK {
QmlComponent qmlc(ba);
}
}
}
void tst_qmlxmlparser::parse_data()
{
QTest::addColumn<QString>("xml");
QTest::addColumn<int> ("parser");
QTest::newRow("empty-qxml")
<< QString()
<< (int)ParserQXmlStreamReader;
QTest::newRow("empty-qml")
<< QString()
<< (int)ParserQmlComponent;
{
QString xml = QString::fromLatin1("<Item prop1=\"foo\"><Prop2 value=\"bar\"/></Item>");
QTest::newRow("simple-qxml")
<< xml
<< (int)ParserQXmlStreamReader;
QTest::newRow("simple-qml")
<< xml
<< (int)ParserQmlComponent;
}
{
QString xml = readFile("concept2.xml");
QTest::newRow("concept2-qxml")
<< xml
<< (int)ParserQXmlStreamReader;
QTest::newRow("concept2-qml")
<< xml
<< (int)ParserQmlComponent;
}
}
QString tst_qmlxmlparser::readFile(QString const& filename)
{
#define _STR(X) #X
#define STR(X) _STR(X)
QFile file(QString("%1/testdata/%2").arg(STR(SRCDIR)).arg(filename));
if (!file.open(QIODevice::ReadOnly)) {
qFatal("Could not open %s: %s", qPrintable(filename), qPrintable(file.errorString()));
}
QByteArray ba = file.readAll();
return QString::fromLatin1(ba);
}
QTEST_MAIN(tst_qmlxmlparser)
#include "main.moc"
|