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

Get help using Construct 2

Post » Sat Nov 01, 2014 2:22 pm

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 ?
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Sat Nov 01, 2014 3:02 pm

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
B
7
S
3
G
1
Posts: 184
Reputation: 1,352

Post » Sat Nov 01, 2014 6:56 pm

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?
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
71
S
19
G
8
Posts: 640
Reputation: 9,701

Post » Sat Nov 01, 2014 7:04 pm

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
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Sat Nov 01, 2014 9:49 pm

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.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Sun Nov 02, 2014 9:03 am

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 : destructible-terrain-kind-of-like-worms_t118319

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 ?
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Sun Nov 02, 2014 9:52 am

Yeah after hearing exactly what your doing I don't see how you can optimize it further.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
71
S
19
G
8
Posts: 640
Reputation: 9,701


Return to How do I....?

Who is online

Users browsing this forum: Christmas, thegodo and 22 guests