Permformance/Coding Inquiry

0 favourites
  • 4 posts
From the Asset Store
5 levels with simple coding Source-code (.c3p) + HTML5 Exported
  • Hi Good day,

    The below coding style produces the same output BUT do they run differently and affect performance?

    I'm planning to insert a lot of data to an array and im wondering whats the best coding style to choose (if they differ in performance)

    Thank you in advance!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi,

    In your second example, you are iterating through an array twice, so it should take more processing time than doing it once. Also, built in array functions may be less CPU consuming than the editor loop you are using. And it could vary greatly depending of the size of your array.

    So the first example may stick to o(n), while the second may be 2 x o(n) in complexity. First is faster.

  • Nabu thank you sir for your response!

  • The cost of executing the actions is the same in both, but in the second example you pay the cost of the loop twice. As well as the setup and teardown, the loop will also do the following for each iteration:

    1. check if loop finished
    2. start of block work
    3. actual actions
    4. end of block work

    The work your actions are doing is the same, so you can ignore that, but the steps in bold are now being done twice per item.

    Now realistically this overhead is fairly minimal, unless you are frequently doing this in your game and the loop is long you are unlikely to notice any difference. I would opt to use whichever is clearer to you, or keeps your game logic simpler. It's worth considering the performance implications of your events, but you should also consider the flexibility and maintainability of your logic. You can always make it less flexible later to improve performance if this particular part proves to be too slow.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)