0 Favourites

How do I know the duration (in real time) of an event ?

  • Hi. I have an event which take some times : like updating thousands of entries in an array. When the event is executed, the computer seems to freeze for a short time.

    Is it possible to know precisely how much time this event takes ?

  • not to my knowledge, however what I have done is count ticks before and after the event... a tick is approximately 15ms (at 60 fps). of course it varies under heavy usage, but it's a good relative indicator..

    what I would do if where you was build in a simple profiler.. I think your problem here is not TIME but CPU utilisation. for me, I set up a simple every 0.1 seconds tick, and stored in an array the cpu usage.. then I displayed the results.. or you could use the debugger.... then you can see what the cpu spiked at.. and for how long..

    lots of tools to help you figure this out.

    PS: doing something like updating thousands of arrays is going to be slow no matter what you do... perhaps you could do it in smaller chunks... do all the elements in the array need to be updated at once.. or could you do it in parts over 5-10 seconds?

    R

  • Do they all need to be updated at once, could you divide the updating between events at different times or even filter out items that haven't changed since last update?

  • You can using the wallclocktime expression. Basically do something like this:

    global number starttime=0

    every tick:

    --- set starttime to wallclocktime

    [some events here]

    every tick

    --- set debug text to wallclocktime-starttime

  • Yikes. Is this for a game, or are you doing a database app? If it's a game, web-workers might let you offload the heavy lifting to another thread. That would require plugin work though.

    Also, if you have a lot of objects, or are generating a massive amount of entries in an array/dictionary, debug mode can slow your project down radically, because it's creating a visual representation of all that data (even if you are not looking at said array/dict).

    Any way to update your database across a number of ticks (limit the maximum number of operations per tick) like rho suggests? Sometimes browsers will crash or throw errors if you try to do too much in a single cycle.

  • I used wallclocktime and it worked perfectly

    What I'm trying to achieve is a destructible terrain "à la Worms", which counts how much pixels were destroyed in order to generate a proper number of particles.

    I first used a loop using "Canvas.alphaAt(X,Y)" for each pixel contained in the radius of the explosion, but r0j0hound suggested that I could store all the Canvas pixels in an array, and iterate over the array because it would be faster.

    That's what I did and it is indeed faster. I first look at all the pixels contained in the explosion radius. For each pixel, I look at its transparency. If its alpha ≠ 0, then I increases the particle quantity variable then I update my array to replace this pixel with a transparent one.

    So this is this step which is slow, but I don't see how I could optimize this, I need to update all these specific pixels in the array, because I compare my collisions with the pixels contained in the array, not with the pixels currently drawn in my canvas (because it's slower).

    I made a thread about this project :

    The elements have to be updated at once, because in my final game, more than 2 projectiles could hit the landscape quickly in the same area.

    chrisinfinger > Because I only update pixels that were not transparent, I think it already works as a filter, sort of. Am I right ?

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Yeah after hearing exactly what your doing I don't see how you can optimize it further.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
282 387,932
Raybrite's avatar
Raybrite
Unread hot topic
234 61,226
DARKSETH's avatar
DARKSETH
Unread hot topic
107 13,191
LeuNoeleeste's avatar
LeuNoeleeste