Thursday, June 11, 2020

Javascript is faster than C++

Can Javascript in QML beat C++ in Speed?

Few have challenged that Javascript can be faster than C++. If one takes the challenge literally, C++ is always faster than Javascript. However, with the overhead of Qt libraries and the QML interpreter, performance can skew dramatically.

Can Javascript be faster than C++? Yes. The following are scenarios where code should be in Javascript instead of C++.

Friday, June 5, 2020

Speed Benchmark: Number crunching in QML versus C++

Performance of Javascript versus C++

The objective is to compute the difference in number crunching performance between:
  • Javascript in QML, versus
  • raw C++

Outcome of Benchmark

Unsurprisingly, Javascript is significantly slower than C++. While it takes Javascript about 2.95 seconds to count from 1 to 1 million, which it takes C++ much lesser than 0.01 second to do the same.

There is no difference in performance between Javascript in .qml file, Javascript in old style Javascript file and Javascript in ECMAScript (ES7) .mjs file.

Wednesday, June 3, 2020

Speed Benchmark: Calling QML function versus Javascript function versus QObject

QML Function Call Performance Comparison

Is calling QML functions faster than calling Javascript functions? How about calling QObject functions? Which has speed advantage?

Note that this is merely calling functions but not running for-loops and while-loops. The intent is to compare this speed of calling Javascript functions to the speed of calling QObjects functions.

Outcome of Benchmark

Surprisingly, calling Javascript .mjs functions (referred to by Qt as ECMAScript modules, which conforms to Javascript ES7 standards) is 40% faster than calling either QML functions or old style Javascript functions.

Calling C++ QObjects from QML is 344% slower than calling another function in a native QML object!

Monday, June 1, 2020

QML Binding Loop (Part 2)

Example 2: Binding Loop Not Related To Sizing a QML object

Most binding loop examples uses sizing and positioning to describe the QML binding loop predicament. The following is an example where a binding loop is evinced without relation to sizing and positioning of QML objects.