Skip to content

Commit

Permalink
Compilation benchmark
Browse files Browse the repository at this point in the history
Change-Id: Iaa875817367d3a9600dd1ad685f996377af9f82d
  • Loading branch information
Aaron Kennedy committed May 5, 2011
1 parent 21521c2 commit 1332e92
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/declarative/qml/parser/qdeclarativejsglobal_p.h
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/declarative/qml/qdeclarativescriptparser_p.h
Expand Up @@ -67,7 +67,7 @@ QT_MODULE(Declarative)
class QByteArray;

class QDeclarativeScriptParserJsASTData;
class QDeclarativeScriptParser
class Q_AUTOTEST_EXPORT QDeclarativeScriptParser
{
public:
class Import
Expand Down
74 changes: 72 additions & 2 deletions tests/benchmarks/declarative/compilation/tst_compilation.cpp
Expand Up @@ -40,9 +40,18 @@
****************************************************************************/

#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
Expand All @@ -58,6 +67,12 @@ class tst_compilation : public QObject
private slots:
void boomblock();

void jsparser_data();
void jsparser();

void scriptparser_data();
void scriptparser();

private:
QDeclarativeEngine engine;
};
Expand Down Expand Up @@ -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"

0 comments on commit 1332e92

Please sign in to comment.