diff options
Diffstat (limited to 'tests/benchmarks/qmlxmlparser')
-rw-r--r-- | tests/benchmarks/qmlxmlparser/main.cpp | 96 | ||||
-rw-r--r-- | tests/benchmarks/qmlxmlparser/qmlxmlparser.pro | 14 | ||||
-rw-r--r-- | tests/benchmarks/qmlxmlparser/testdata/concept2.xml | 421 |
3 files changed, 531 insertions, 0 deletions
diff --git a/tests/benchmarks/qmlxmlparser/main.cpp b/tests/benchmarks/qmlxmlparser/main.cpp new file mode 100644 index 0000000..17dc7f3 --- /dev/null +++ b/tests/benchmarks/qmlxmlparser/main.cpp @@ -0,0 +1,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" diff --git a/tests/benchmarks/qmlxmlparser/qmlxmlparser.pro b/tests/benchmarks/qmlxmlparser/qmlxmlparser.pro new file mode 100644 index 0000000..e31c692 --- /dev/null +++ b/tests/benchmarks/qmlxmlparser/qmlxmlparser.pro @@ -0,0 +1,14 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_qmlxmlparser +DEPENDPATH += . +INCLUDEPATH += . + +CONFIG += release + +QT += declarative xml + +DEFINES+=SRCDIR=\"$$PWD\" + +# Input +SOURCES += main.cpp diff --git a/tests/benchmarks/qmlxmlparser/testdata/concept2.xml b/tests/benchmarks/qmlxmlparser/testdata/concept2.xml new file mode 100644 index 0000000..67c625d --- /dev/null +++ b/tests/benchmarks/qmlxmlparser/testdata/concept2.xml @@ -0,0 +1,421 @@ +<Item id="Screen" width="320" height="240"> + <Item id="Main" anchors.fill="{parent}"> + + <Script source="concept2.js"/> + + <resources> + + <ListModel id="TabModel"> + <ListItem> + <name>Favorites</name> + <image>pics/favorites.png</image> + <highlightColor>#BE0000</highlightColor> + </ListItem> + <ListItem> + <name>Phone</name> + <image>pics/calls.png</image> + <highlightColor>#BE00B5</highlightColor> + </ListItem> + <ListItem> + <name>Messages</name> + <image>pics/messaging.png</image> + <highlightColor>#1000BE</highlightColor> + </ListItem> + <ListItem> + <name>Applications</name> + <image>pics/apps.png</image> + <highlightColor>#00AEBE</highlightColor> + </ListItem> + <ListItem> + <name>Media Center</name> + <image>pics/media.png</image> + <highlightColor>#06BE00</highlightColor> + </ListItem> + <ListItem> + <name>Settings</name> + <image>pics/settings.png</image> + <highlightColor>#CF7900</highlightColor> + </ListItem> + </ListModel> + + <ListModel id="ListModel1"> + <ListItem> + <name>Games</name> + </ListItem> + <ListItem> + <name>Contacts</name> + </ListItem> + <ListItem> + <name>Clock</name> + </ListItem> + </ListModel> + + <ListModel id="ListModel2"> + <ListItem> + <name>Contacts</name> + </ListItem> + <ListItem> + <name>Missed Calls</name> + </ListItem> + <ListItem> + <name>Received Calls</name> + </ListItem> + <ListItem> + <name>Dialed Numbers</name> + </ListItem> + </ListModel> + + <ListModel id="ListModel3"> + <ListItem> + <name>Inbox</name> + </ListItem> + <ListItem> + <name>Sent</name> + </ListItem> + <ListItem> + <name>Drafts</name> + </ListItem> + <ListItem> + <name>Email</name> + </ListItem> + </ListModel> + + <ListModel id="ListModel4"> + <ListItem> + <name>Calculator</name> + </ListItem> + <ListItem> + <name>Calendar</name> + </ListItem> + <ListItem> + <name>Camera</name> + </ListItem> + <ListItem> + <name>Clock</name> + </ListItem> + <ListItem> + <name>Notes</name> + </ListItem> + <ListItem> + <name>Web Browser</name> + </ListItem> + </ListModel> + + <ListModel id="ListModel5"> + <ListItem> + <name>Pictures</name> + </ListItem> + <ListItem> + <name>Music</name> + </ListItem> + <ListItem> + <name>Videos</name> + </ListItem> + <ListItem> + <name>Games</name> + </ListItem> + </ListModel> + + <ListModel id="ListModel6"> + <ListItem> + <name>Appearance</name> + </ListItem> + <ListItem> + <name>Bluetooth</name> + </ListItem> + <ListItem> + <name>Date/Time</name> + </ListItem> + <ListItem> + <name>Power Management</name> + </ListItem> + </ListModel> + + <ListModel id="AlarmsModel"> + <ListItem> + <time>7:30</time> + <label>Wake Up!</label> + <repeat>Weekdays</repeat> + <status>on</status> + </ListItem> + <ListItem> + <time>9:00</time> + <label>Exercise</label> + <repeat>Weekends</repeat> + <status>on</status> + </ListItem> + </ListModel> + + <Component id="TabDelegate"> + <Item width="53" height="36"> + <Image file="{image}" x="15" y="7" /> + <ColorAnimation target="{TitleBar}" property="highlightColor" running="{index == TabListView.currentIndex}" to="{highlightColor}" duration="300"/> + <NumericAnimation target="{Lists}" property="x" running="{index == TabListView.currentIndex}" to="{-TabListView.currentIndex * 320}" duration="300" easing="easeInOutQuad"/> + <Bind target="{Title}" property="text" value="{if (index == TabListView.currentIndex) name;}"/> + </Item> + </Component> + + <Component id="TabHighlight"> + <Image file="titlebar-selection.png"/> + </Component> + + <Component id="ListDelegate"> + <Item x="12" width="{Main.width}" height="30"> + <Text id="AppNameBlack" text="{name}" width="{parent.width}" height="{parent.height}" vAlign="AlignVCenter" font.size="10" font.bold="true" font.family="Nokia Standard Multiscript"/> + <Text id="AppNameWhite" text="{name}" width="{parent.width}" height="{parent.height}" vAlign="AlignVCenter" font.size="10" font.bold="true" font.family="Nokia Standard Multiscript" color="white" opacity="0"/> + <states> + <State name="currentItem" when="{list.currentIndex == index}"> + <SetProperty target="{AppNameBlack}" property="opacity" value="0"/> + <SetProperty target="{AppNameWhite}" property="opacity" value="1"/> + </State> + </states> + <transitions> + <Transition> + <NumericAnimation property="opacity" duration="250"/> + </Transition> + </transitions> + </Item> + </Component> + + <Component id="ContactDelegate"> + <KeyActions id="Wrapper" width="{Main.width}" focusable="true" height="30" + leftArrow="PhoneDetails.currentState='BusinessDetails'" + rightArrow="PhoneDetails.currentState='BusinessDetails'"> + + <!--<Rect id="Highlight" width="{Main.width - 6}" x="3" radius="4" height="60" color="black" opacity="0"/>--> + <Image id="Portrait" file="{portrait}" x="10" y="5" opacity="0"/> + <Item id="ContactName" x="18" y="5"> + <Text id="NameBlack" text="{firstName + ' '+ lastName}" font.size="10" font.bold="true" font.family="Nokia Standard Multiscript"/> + <Text id="NameWhite" text="{firstName + ' '+ lastName}" font.size="10" font.bold="true" font.family="Nokia Standard Multiscript" color="white" opacity="0"/> + </Item> + <Item id="PhoneDetails" opacity="0"> + <Item id="HomeDetails"> + <Image file="pics/homephone.png" x="75" y="30"/> + <Text text="{homephone}" x="105" y="33" font.size="10" font.bold="true" font.family="Nokia Standard Multiscript" color="white"/> + </Item> + <Item id="BusinessDetails" opacity="0"> + <Image file="pics/businessmobile.png" x="75" y="30"/> + <Text text="{businessmobile}" x="105" y="33" font.size="10" font.bold="true" font.family="Nokia Standard Multiscript" color="white"/> + </Item> + <states> + <State name="BusinessDetails"> + <SetProperty target="{HomeDetails}" property="opacity" value="0"/> + <SetProperty target="{BusinessDetails}" property="opacity" value="1"/> + <SetProperties target="{Wrapper}" leftArrow="PhoneDetails.currentState=''" rightArrow="PhoneDetails.currentState=''" /> + </State> + </states> + <transitions> + <Transition> + <NumericAnimation properties="opacity" duration="250"/> + </Transition> + </transitions> + </Item> + <states> + <State name="currentItem" when="{list.currentIndex == index}"> + <SetProperty target="{Wrapper}" property="focus" value="true"/> + <SetProperty target="{NameBlack}" property="opacity" value="0"/> + <SetProperty target="{NameWhite}" property="opacity" value="1"/> + <SetProperty target="{Wrapper}" property="height" value="60" /> + <SetProperty target="{Portrait}" property="opacity" value="1" /> + <SetProperty target="{ContactName}" property="x" value="70" /> + <SetProperty target="{PhoneDetails}" property="opacity" value="1" /> + <SetProperty target="{Highlight}" property="opacity" value="1" /> + </State> + </states> + <transitions> + <Transition> + <NumericAnimation properties="opacity,height,y,x" duration="250"/> + </Transition> + </transitions> + </KeyActions> + </Component> + + <Component id="ListHighlight"> + <Item> + <Rect width="{Main.width-6}" x="-9" height="{parent.height}" color="#242424" radius="4"/> + </Item> + </Component> + + <Component id="AlarmsDelegate"> + <KeyActions id="Wrapper" width="{Main.width}" focusable="true" height="60" escape="Wrapper.currentState = 'currentItem'" return="Wrapper.currentState = 'EditMode'"> + <Image file="pics/alarm.png" x="10" anchors.verticalCenter="{parent.verticalCenter}"/> + <Text id="TimeBlack" text="{time}" anchors.verticalCenter="{parent.verticalCenter}" x="50" font.size="16" font.bold="true" font.family="Nokia Large"/> + <Text id="TimeWhite" text="{time}" anchors.verticalCenter="{parent.verticalCenter}" x="50" font.size="16" font.bold="true" font.family="Nokia Large" color="white" opacity="0"/> + <Text id="LabelBlack" text="{label}" x="110" y="4" font.size="10" font.bold="true" font.family="Nokia Standard Multiscript"/> + <Text id="LabelWhite" text="{label}" x="110" y="4" font.size="10" font.bold="true" font.family="Nokia Standard Multiscript" color="white" opacity="0"/> + <Text id="RepeatBlack" text="{repeat}" x="110" y="25" font.size="10" font.family="Nokia Standard Multiscript"/> + <Text id="RepeatWhite" text="{repeat}" x="110" y="25" font.size="10" font.family="Nokia Standard Multiscript" color="white" opacity="0"/> + <states> + <State name="currentItem" when="{list.currentIndex == index}"> + <SetProperty target="{Wrapper}" property="focus" value="true"/> + <SetProperty target="{TimeBlack}" property="opacity" value="0"/> + <SetProperty target="{TimeWhite}" property="opacity" value="1"/> + <SetProperty target="{LabelBlack}" property="opacity" value="0"/> + <SetProperty target="{LabelWhite}" property="opacity" value="1"/> + <SetProperty target="{RepeatBlack}" property="opacity" value="0"/> + <SetProperty target="{RepeatWhite}" property="opacity" value="1"/> + </State> + <State name="EditMode" extends="currentItem"> + <SetProperty target="{list}" property="x" value="-320"/> + <SetProperty target="{AlarmDetails}" property="active" value="true"/> + </State> + </states> + <transitions> + <Transition> + <NumericAnimation properties="opacity,height,y,x,yPosition" duration="250"/> + </Transition> + </transitions> + </KeyActions> + </Component> + + </resources> + + <Image id="Background" file="pics/background.png" opaque="true"/> + + <Item id="TitleBar"> + <properties> + <Property name="index" value="0" type="Int"/> + <Property name="highlightColor" type="Color"/> + </properties> + <Rect id="TitleBarBackground" y="0" gradientColor="black" color="{'#676767'}" width="320" height="24"/> + <Image id="HeaderShadow" file="pics/header-shadow.png" anchors.top="{TitleBarBackground.bottom}" width="320"/> + <Item id="TitleBarContent" width="320" height="24"> + <Text id="Operator" text="Qt Extended" x="5" style="Sunken" styleColor="#333333" width="155" height="{parent.height}" color="white" font.size="10" font.bold="true" font.family="Nokia Standard Multiscript" vAlign="AlignVCenter"/> + <Text id="Title" text="" x="5" style="Sunken" styleColor="#333333" width="155" height="{parent.height}" color="white" font.size="10" font.bold="true" font.family="Nokia Standard Multiscript" vAlign="AlignVCenter" opacity="0"/> + <Text id="Time" text="10:52 AM" style="Sunken" styleColor="#333333" x="160" width="155" height="{parent.height}" color="white" font.size="10" font.bold="true" font.family="Nokia Standard Multiscript" hAlign="AlignRight" vAlign="AlignVCenter"/> + </Item> + <ListView id="TabListView" currentIndex="{TitleBar.index}" y="24" width="320" height="36" model="{TabModel}" delegate="{TabDelegate}" highlight="{TabHighlight}" clip="true" currentItemMode="Click" orientation="Qt::Horizontal" opacity="0"/> + <states> + <State name="coloredState"> + <SetProperty target="{TitleBarBackground}" property="color" binding="TitleBar.highlightColor" /> + <SetProperty target="{MenuBarBackground}" property="color" binding="TitleBar.highlightColor" /> + </State> + <State name="Expanded" extends="coloredState"> + <SetProperty target="{TitleBarBackground}" property="height" value="60"/> + <SetProperty target="{TabListView}" property="opacity" value="1"/> + <SetProperty target="{Lists}" property="y" value="63"/> + <SetProperty target="{Title}" property="opacity" value="1"/> + <SetProperty target="{Operator}" property="x" value="-155"/> + <SetProperty target="{ListBackground}" property="y" value="60"/> + <SetProperty target="{List1}" property="focus" value="true"/> + <SetProperty target="{HeaderShadow}" property="opacity" value="0"/> + <SetProperty target="{ContextKey2}" property="text" value="Select"/> + <SetProperty target="{ContextKey3}" property="text" value="Back"/> + </State> + <State name="ApplicationLaunched" extends="coloredState"> + <SetProperty target="{Lists}" property="opacity" value="0"/> + <SetProperty target="{Title}" property="opacity" value="1"/> + <SetProperty target="{Operator}" property="x" value="-155"/> + <SetProperty target="{ListBackground}" property="y" value="24"/> + <SetProperty target="{ContextKey2}" property="text" value="Select"/> + <SetProperty target="{ContextKey3}" property="text" value="Back"/> + </State> + <State name="ContactsLaunched" extends="ApplicationLaunched"> + <SetProperty target="{ContactList}" property="focus" value="true"/> + <SetProperty target="{ContactList}" property="opacity" value="1"/> + </State> + <State name="AlarmsLaunched" extends="ApplicationLaunched"> + <SetProperty target="{AlarmList}" property="focus" value="true"/> + <SetProperty target="{AlarmList}" property="opacity" value="1"/> + </State> + </states> + <transitions> + <Transition fromState="*" toState="Expanded" reversible="true"> + <SerialAnimation> + <NumericAnimation properties="x,y,height" easing="easeInOutQuad" duration="300"/> + <NumericAnimation properties="opacity" duration="200"/> + </SerialAnimation> + </Transition> + <Transition fromState="Expanded" toState="ContactsLaunched" reversible="true"> + <NumericAnimation properties="x,y,height,opacity" easing="easeInOutQuad" duration="300"/> + </Transition> + <Transition fromState="Expanded" toState="AlarmsLaunched" reversible="true"> + <NumericAnimation properties="x,y,height,opacity" easing="easeInOutQuad" duration="300"/> + </Transition> + </transitions> + </Item> + + <Rect id="ListBackground" color="#cdcdcd" y="237" width="320" height="216"/> + <Item id="Lists" y="240" width="320" height="150" onKeyPress="keyPressed(event.key)"> + <ListView id="List1" focusable="true" focus="true" width="{parent.width}" height="150" model="{ListModel1}" delegate="{ListDelegate}" clip="true" currentItemMode="Click" highlight="{ListHighlight}" wrap="true"/> + <ListView id="List2" focusable="true" x="320" width="{parent.width}" height="150" model="{ListModel2}" delegate="{ListDelegate}" clip="true" currentItemMode="Click" highlight="{ListHighlight}" wrap="true"/> + <ListView id="List3" focusable="true" x="640" width="{parent.width}" height="150" model="{ListModel3}" delegate="{ListDelegate}" clip="true" currentItemMode="Click" highlight="{ListHighlight}" wrap="true"/> + <ListView id="List4" focusable="true" x="960" width="{parent.width}" height="150" model="{ListModel4}" delegate="{ListDelegate}" clip="true" currentItemMode="Click" highlight="{ListHighlight}" wrap="true"/> + <ListView id="List5" focusable="true" x="1280" width="{parent.width}" height="150" model="{ListModel5}" delegate="{ListDelegate}" clip="true" currentItemMode="Click" highlight="{ListHighlight}" wrap="true"/> + <ListView id="List6" focusable="true" x="1600" width="{parent.width}" height="150" model="{ListModel6}" delegate="{ListDelegate}" clip="true" currentItemMode="Click" highlight="{ListHighlight}" wrap="true"/> + </Item> + + <ListView id="ContactList" model="{contactModel}" y="27" height="186" width="320" opacity="0" clip="true" focusable="true" focus="false" delegate="{ContactDelegate}" currentItemMode="Click" onKeyPress="contactsKeyPressed(event.key)"> + <children> + <Rect color="#242424" radius="4" width="320" height="60" id="ContactListRect" y="{ContactList.currentIndex * 30}"> + <Text text="{parent.y}" color="white" anchors.right="{parent.right}"/> + <y> + <Behaviour> + <NumericAnimation property="y" duration="250" /> + </Behaviour> + </y> + </Rect> + </children> + </ListView> + <ListView id="AlarmList" model="{AlarmsModel}" y="27" height="186" width="320" clip="true" focusable="true" focus="false" delegate="{AlarmsDelegate}" highlight="{ListHighlight}" currentItemMode="Click" onKeyPress="alarmKeyPressed(event.key)" opacity="0"/> + <FocusPanel id="AlarmDetails" anchors.left="{AlarmList.right}" y="27" height="186" width="320" active="false"> + <VerticalLayout anchors.fill="{parent}"> + <EditableText id="et1" label="Label" focus="true" text="Wake Up!" height="40" width="{AlarmList.width}"/> + <EditableText id="et2" label="Time" text="07:45" height="40" width="{AlarmList.width}"/> + <EditableText id="et3" label="Frequency" text="Weekdays" height="40" width="{AlarmList.width}"/> + </VerticalLayout> + </FocusPanel> + +<!-- <Clock id="Clock" x="70" y="30" opacity="0" hour="2" minute="59" focusable="true" onKeyPress="keyPressed(event.key)"/>--> + + <Rect id="MenuBarBackground" gradientColor="black" color="{'#676767'}" y="216" width="320" height="24" /> + <FocusPanel active="{currentState=='ToolBar'}" id="MenuBar" y="216" width="320" height="24"> + <KeyActions c="MenuBar.currentState=''" focusable="true" focus="true" /> + <Rect width="{MenuBar.width}" height="1" color="black" opacity="0.2"/> + <Item id="ContextKeys" anchors.fill="{parent}"> + <states> + <State name="Hidden" when="{QuickMenu.expanded == true}"> + <SetProperty target="{ContextKeys}" property="opacity" value="0" /> + </State> + </states> + <transitions> + <Transition> + <NumericAnimation properties="opacity" duration="300" /> + </Transition> + </transitions> + + <SoftText id="ContextKey1" text="Options" anchors.verticalCenter="{parent.verticalCenter}" x="35" /> + <SoftText id="ContextKey2" text="Menu" anchors.horizontalCenter="{parent.horizontalCenter}" anchors.verticalCenter="{parent.verticalCenter}" /> + <SoftText id="ContextKey3" text="" anchors.verticalCenter="{parent.verticalCenter}" x="290" /> + <MouseRegion height="{parent.height}" width="106" onClick="contextKey1Cliked();"/> + <MouseRegion height="{parent.height}" x="107" width="106" onClick="contextKey2Cliked();"/> + <MouseRegion height="{parent.height}" x="213" width="106" onClick="contextKey3Cliked();"/> + </Item> + <HorizontalLayout id="ToolBar" opacity="0"> + <ToolButton id="NewButton" text="New" icon="pics/document-new.png"/> + <ToolButton id="EditButton" text="Edit" icon="pics/edit-rename.png"/> + <ToolButton id="DeleteButton" text="Delete" icon="pics/edit-delete.png"/> + <ToolButton id="DeleteButton2" text="Delete" icon="pics/edit-delete.png"/> + </HorizontalLayout> + <states> + <State name="ToolBar"> + <SetProperty target="{MenuBarBackground}" property="y" value="180"/> + <SetProperty target="{MenuBarBackground}" property="height" value="62"/> + <SetProperty target="{MenuBar}" property="y" value="180"/> + <SetProperty target="{MenuBar}" property="height" value="60"/> + <SetProperty target="{ContextKeys}" property="opacity" value="0"/> + <SetProperty target="{ToolBar}" property="opacity" value="1"/> + </State> + </states> + <transitions> + <Transition fromState="*" toState="ToolBar" reversible="true"> + <NumericAnimation properties="y,height,opacity" easing="easeInOutQuad" duration="250"/> + </Transition> + </transitions> + </FocusPanel> + + </Item> + + <CallMenu id="QuickMenu"/> + +</Item> |