Efficiancy

I have been using game maker for a while now. I have a pretty good understanding of the mechanics now.

However, Gamemaker is still a black box. What I would like to know is which functions are more CPU efficient than others.

For example, if I do a draw_somthing is that more or less efficient than tilemap_set.

What about an instance of an object. Is that better than a point_in_rectangle on a drawing?

Idon'treally require a direct example for each, allthough this would be very helpful. My question is how do I know for sure which functions are more efficient than another.
 

Simon Gust

Member
It's better to know how you can test these things yourself.
Code:
var t = get_timer();
// ---------------------------------------
// code start



// code end
// ---------------------------------------
var t = get_timer() - t;
show_debug_message(t);
If you put a function between the code start and code end sections, "t" will give you the time that has passed since then in microseconds I believe.
The result is displayed in your console.
 
M

MarisFrance

Guest
If test code is too fast (faster than 1ms)...
Code:
var t = current_time;
for (i=0; i<1000; i++)
{
     // ---------------------------------------
     // test code start



     // test code end
     // ---------------------------------------
}
show_message(string(current_time - t) + " ms");
 
The above is what I use. Also, remember to run it multiple times to make sure it's persistent and/or give a reasonable min, max and mean value.

Code:
vmin = 999999999
vmax = 0
avg = 0

//in loop...
vmin = min(vmin, value)
vmax = max(vmax, t)
avg += value

//after loop...
avg /= loop_iterations
 

Smiechu

Member
Also bare in mind that CPU is not everything, and the things happening by GPU are in most cases more critical to the performance. This is important as you mentioned about drawing. Here i.e. size of the texture page could have influence on performance of some draw functions, etc...

In genreal - collisions and manipulation on large data chunks are loading the cpu the most.
By drawing - operations on surfaces are eating performance quite quic.
 
Does GMS2 come with any tools that allow you to see if how much GPU and or system memory is being used? I guess I could use third party tools post-compile.

I don't think with the project I am working on especially in 2D is going to have no visible effect no matter how badly it's been implemented due to the power of computers these days but I do like to do thing correctly.

Thanks for all your help guys.
 

Simon Gust

Member
You have
Code:
show_debug_overlay(1);
at your disposal.
It shows the general strain on your cpu and gpu, how many times the using texture is swapped and how many times the draw batch is broken.
 

Smiechu

Member
Does GMS2 come with any tools that allow you to see if how much GPU and or system memory is being used? I guess I could use third party tools post-compile.

I don't think with the project I am working on especially in 2D is going to have no visible effect no matter how badly it's been implemented due to the power of computers these days but I do like to do thing correctly.

Thanks for all your help guys.
1. Yes, you have also quite nice debugger to your disposal.
2. You'll be very unpleasantly surprised how easy it is to "stuck" the 2D graphic pipeline.
 
Top