Efficiancy

Discussion in 'Programming' started by Daniel Mallett, Aug 13, 2018.

Tags:
  1. Daniel Mallett

    Daniel Mallett Member

    Joined:
    Aug 24, 2017
    Posts:
    152
    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.
     
  2. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,182
    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.
     
  3. Daniel Mallett

    Daniel Mallett Member

    Joined:
    Aug 24, 2017
    Posts:
    152
    Thats cool. I did not know that. Thank you.
     
  4. MarisFrance

    MarisFrance Member

    Joined:
    Jul 26, 2018
    Posts:
    22
    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");
     
    Carl Nylander likes this.
  5. Carl Nylander

    Carl Nylander Member

    Joined:
    Jul 21, 2016
    Posts:
    212
    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
     
  6. Daniel Mallett

    Daniel Mallett Member

    Joined:
    Aug 24, 2017
    Posts:
    152
    Cool thanks man.
     
  7. Smiechu

    Smiechu Member

    Joined:
    Jul 14, 2017
    Posts:
    626
    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.
     
  8. Daniel Mallett

    Daniel Mallett Member

    Joined:
    Aug 24, 2017
    Posts:
    152
    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.
     
  9. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,182
    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.
     
    Lazzeking likes this.
  10. Lazzeking

    Lazzeking Member

    Joined:
    May 3, 2018
    Posts:
    29
    Was just about to say that , guess I'm too slow.
     
    Simon Gust likes this.
  11. Smiechu

    Smiechu Member

    Joined:
    Jul 14, 2017
    Posts:
    626
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice