Compilation benchmark
authorAaron Kennedy <aaron.kennedy@nokia.com>
Thu, 5 May 2011 05:24:17 +0000 (15:24 +1000)
committerAaron Kennedy <aaron.kennedy@nokia.com>
Thu, 5 May 2011 05:26:17 +0000 (15:26 +1000)
Change-Id: Iaa875817367d3a9600dd1ad685f996377af9f82d

src/declarative/qml/parser/qdeclarativejsglobal_p.h
src/declarative/qml/qdeclarativescriptparser_p.h
tests/benchmarks/declarative/compilation/tst_compilation.cpp

index 776937c..4fd8b84 100644 (file)
@@ -58,7 +58,7 @@
 #else // !QT_CREATOR
 #  define QT_QML_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
 #  define QT_QML_END_NAMESPACE QT_END_NAMESPACE
-#  define QML_PARSER_EXPORT
+#  define QML_PARSER_EXPORT Q_AUTOTEST_EXPORT
 #endif // QT_CREATOR
 
 #endif // QDECLARATIVEJSGLOBAL_P_H
index fd89f75..f8cea76 100644 (file)
@@ -67,7 +67,7 @@ QT_MODULE(Declarative)
 class QByteArray;
 
 class QDeclarativeScriptParserJsASTData;
-class QDeclarativeScriptParser
+class Q_AUTOTEST_EXPORT QDeclarativeScriptParser
 {
 public:
     class Import
index 7bf6c9d..e09b340 100644 (file)
 ****************************************************************************/
 
 #include <qtest.h>
-#include <QDeclarativeEngine>
-#include <QDeclarativeComponent>
+
+#include <QtDeclarative/qdeclarativeengine.h>
+#include <QtDeclarative/qdeclarativecomponent.h>
+#include <QtDeclarative/private/qdeclarativejsengine_p.h>
+#include <QtDeclarative/private/qdeclarativejsnodepool_p.h>
+#include <QtDeclarative/private/qdeclarativejsparser_p.h>
+#include <QtDeclarative/private/qdeclarativejslexer_p.h>
+#include <QtDeclarative/private/qdeclarativescriptparser_p.h>
+
 #include <QFile>
+#include <QDebug>
+#include <QTextStream>
 
 #ifdef Q_OS_SYMBIAN
 // In Symbian OS test data is located in applications private dir
@@ -58,6 +67,12 @@ public:
 private slots:
     void boomblock();
 
+    void jsparser_data();
+    void jsparser();
+
+    void scriptparser_data();
+    void scriptparser();
+
 private:
     QDeclarativeEngine engine;
 };
@@ -90,6 +105,61 @@ void tst_compilation::boomblock()
     }
 }
 
+void tst_compilation::jsparser_data()
+{
+    QTest::addColumn<QString>("file");
+
+    QTest::newRow("boomblock") << QString(SRCDIR + QLatin1String("/data/BoomBlock.qml"));
+}
+
+void tst_compilation::jsparser()
+{
+    QFETCH(QString, file);
+
+    QFile f(file);
+    QVERIFY(f.open(QIODevice::ReadOnly));
+    QByteArray data = f.readAll();
+
+    QTextStream stream(data, QIODevice::ReadOnly);
+    const QString code = stream.readAll();
+
+    QBENCHMARK {
+        QDeclarativeJS::Engine engine;
+        QDeclarativeJS::NodePool nodePool(file, &engine);
+
+        QDeclarativeJS::Lexer lexer(&engine);
+        lexer.setCode(code, -1);
+
+        QDeclarativeJS::Parser parser(&engine);
+        parser.parse();
+        parser.ast();
+    }
+}
+
+void tst_compilation::scriptparser_data()
+{
+    QTest::addColumn<QString>("file");
+
+    QTest::newRow("boomblock") << QString(SRCDIR + QLatin1String("/data/BoomBlock.qml"));
+}
+
+void tst_compilation::scriptparser()
+{
+    QFETCH(QString, file);
+
+    QFile f(file);
+    QVERIFY(f.open(QIODevice::ReadOnly));
+    QByteArray data = f.readAll();
+
+    QUrl url = QUrl::fromLocalFile(file);
+
+    QBENCHMARK {
+        QDeclarativeScriptParser parser;
+        parser.parse(data, url);
+        parser.tree();
+    }
+}
+
 QTEST_MAIN(tst_compilation)
 
 #include "tst_compilation.moc"