An interesting look at Flood Fill Algorithm implemented in C++ vs QML Javascript



  • I want to preface by saying I’m very new to Javascript.
    Here is the video:
    https://youtu.be/M2_aYzdMAcw

    This was written using the Qt framework, which I’m sure adds even more overhead to the javascript code, so take it with a grain of salt.

    Part of a game I’m working on is similar to a paint application. Originally, since the front end is written in QML, I wrote the flood fill algorithm for the paint bucket in javascript, which worked perfectly fine for filling in enclosed items, or if the window was small. If the window was maximized and the paint bucket was requested on the background; however, it seemed the application would hang for a few seconds and then finally finish. I figured that’s just how it was going to be since there are a lot of pixels to iterate through, but during game testing with my friends it was a feature that was discussed a lot. I decided to rewrite the same exact paint bucket in c++. Even with the added code to save the image and then read the image, the algorithm implemented in c++ was much, much quicker.

    Javascript Results output:

    qml: 11:06:39 AM EDT <- paint bucket started on enclosed shape

    qml: 11:06:39 AM EDT <- paint bucket finished on enclosed shape

    qml: 11:06:40 AM EDT <- paint bucket started on background

    qml: 11:06:45 AM EDT <- paint bucket finished on background

    C++ Results output:

    qml: 11:06:58 AM EDT <- paint bucket started on enclosed shape

    qml: 11:06:58 AM EDT <- paint bucket finished on enclosed shape

    qml: 11:06:59 AM EDT <- paint bucket started on background

    qml: 11:07:00 AM EDT <- paint bucket finished on background

    Source can be found here:
    https://gitlab.com/tenkohms/CPPvsJavascript_PaintBucket

    Quick plug, if you want to check out my slow moving kickstarter of the game I made that uses this paint code:

    kickstarter.com/projects/370338426/scribble-0/


  • Moderators

    @TenKOhms said in An interesting look at Flood Fill Algorithm implemented in C++ vs QML Javascript:

    ven with the added code to save the image and then read the image, the algorithm implemented in c++ was much, much quicker

    Yep, never use JavaScript for anything but very simple GUI logic.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.