diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-12-02 01:08:59 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-12-02 01:08:59 (GMT) |
commit | 0eb70ae512c68fed6caf6f9b4bc8675b90100acf (patch) | |
tree | f7199a53ec59eee7589dbde86036265d3c257770 /tests/benchmarks/declarative/qmltime | |
parent | 2e0eae3e7f5c72bba7aee43366618edf2cfc4b06 (diff) | |
download | Qt-0eb70ae512c68fed6caf6f9b4bc8675b90100acf.zip Qt-0eb70ae512c68fed6caf6f9b4bc8675b90100acf.tar.gz Qt-0eb70ae512c68fed6caf6f9b4bc8675b90100acf.tar.bz2 |
QML timing utility
Diffstat (limited to 'tests/benchmarks/declarative/qmltime')
-rw-r--r-- | tests/benchmarks/declarative/qmltime/example.qml | 14 | ||||
-rw-r--r-- | tests/benchmarks/declarative/qmltime/qmltime.cpp | 133 | ||||
-rw-r--r-- | tests/benchmarks/declarative/qmltime/qmltime.pro | 8 |
3 files changed, 155 insertions, 0 deletions
diff --git a/tests/benchmarks/declarative/qmltime/example.qml b/tests/benchmarks/declarative/qmltime/example.qml new file mode 100644 index 0000000..68889f0 --- /dev/null +++ b/tests/benchmarks/declarative/qmltime/example.qml @@ -0,0 +1,14 @@ +import Qt 4.6 +import QmlTime 1.0 as QmlTime + +Item { + + property string name: "Bob Smith" + + QmlTime.Timer { + component: Item { + Text { text: name } + } + } +} + diff --git a/tests/benchmarks/declarative/qmltime/qmltime.cpp b/tests/benchmarks/declarative/qmltime/qmltime.cpp new file mode 100644 index 0000000..918c197 --- /dev/null +++ b/tests/benchmarks/declarative/qmltime/qmltime.cpp @@ -0,0 +1,133 @@ +#include <QmlEngine> +#include <QmlComponent> +#include <QDebug> +#include <QApplication> +#include <QTime> +#include <QmlContext> + +class Timer : public QObject +{ + Q_OBJECT + Q_PROPERTY(QmlComponent *component READ component WRITE setComponent); + +public: + Timer(); + + QmlComponent *component() const; + void setComponent(QmlComponent *); + + static Timer *timerInstance(); + + void run(uint); + +private: + QmlComponent *m_component; + static Timer *m_timer; +}; +QML_DECLARE_TYPE(Timer); +QML_DEFINE_TYPE(QmlTime, 1, 0, Timer, Timer); + +Timer *Timer::m_timer = 0; + +Timer::Timer() +: m_component(0) +{ + if (m_timer) + qWarning("Timer: Timer already registered"); + m_timer = this; +} + +QmlComponent *Timer::component() const +{ + return m_component; +} + +void Timer::setComponent(QmlComponent *c) +{ + m_component = c; +} + +Timer *Timer::timerInstance() +{ + return m_timer; +} + +void Timer::run(uint iterations) +{ + QmlContext context(qmlContext(this)); + + QTime t; + t.start(); + for (uint ii = 0; ii < iterations; ++ii) { + QObject *o = m_component->create(&context); + delete o; + } + + int e = t.elapsed(); + + qWarning() << "Total:" << e << "ms, Per iteration:" << qreal(e) / qreal(iterations) << "ms"; + +} + +void usage(const char *name) +{ + qWarning("Usage: %s [-iterations <count>] <qml file>", name); + exit(-1); +} + +int main(int argc, char ** argv) +{ + QApplication app(argc, argv); + + uint iterations = 1024; + QString filename; + + for (int ii = 1; ii < argc; ++ii) { + QByteArray arg(argv[ii]); + + if (arg == "-iterations") { + if (ii + 1 < argc) { + ++ii; + QByteArray its(argv[ii]); + bool ok = false; + iterations = its.toUInt(&ok); + if (!ok) + usage(argv[0]); + } else { + usage(argv[0]); + } + } else { + filename = QLatin1String(argv[ii]); + } + } + + QmlEngine engine; + QmlComponent component(&engine, filename); + if (component.isError()) { + qWarning() << component.errors(); + return -1; + } + + QObject *obj = component.create(); + if (!obj) { + qWarning() << component.errors(); + return -1; + } + + Timer *timer = Timer::timerInstance(); + if (!timer) { + qWarning() << "A Tester.Timer instance is required."; + return -1; + } + + if (!timer->component()) { + qWarning() << "The timer has no component"; + return -1; + } + + timer->run(iterations); + + return 0; +} + +#include "tst_delegate.moc" diff --git a/tests/benchmarks/declarative/qmltime/qmltime.pro b/tests/benchmarks/declarative/qmltime/qmltime.pro new file mode 100644 index 0000000..b077d1a --- /dev/null +++ b/tests/benchmarks/declarative/qmltime/qmltime.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = qmltime +QT += declarative +macx:CONFIG -= app_bundle + +SOURCES += qmltime.cpp + |