GM:S 1.4 [SOLVED]Does DCE exists in GMS 1.4?

Discussion in 'Programming' started by Paskaler, Jul 5, 2018.

  1. Paskaler

    Paskaler Member

    Joined:
    Jul 4, 2016
    Posts:
    315
    I've read somewhere on the forums that constant expressions will get evaluated at compile time, but I can't find the post and I'm unsure whether or not this is a GMS 2 only thing. I'd also like to add that I'm using the Early Access version of GMS in case it only exists there.

    So, I have a macro defined DEBUG as true. If I change it to false, what would happen to code like this:
    Code:
    if DEBUG {
       show_debug_message( "hello" );
    }
    
    Will the compiler simply remove the entire thing, as there is no chance of ever running that code. I'm asking this since, up to now, I've had a weird obsession of adding debug code only when something breaks and removing it immediately after I fix the part that wasn't working and this means that there are times when I remove and the re-add the same debug code and this can get pretty annoying. So, basically, if this gets removed by the compiler, that means that I don't have to fix my silly OCD :D
     
  2. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    You can easily test this yourself.

    Use this code to compare MACRO speed:
    Code:
    var t = current_time;
    
    repeat 100000000 {
        if DEBUG {
            show_message("hi");
        }
    }
    
    show_message(current_time - t);
    This code to compare commented speed:
    Code:
    var t = current_time;
    
    repeat 100000000 {
    //    if DEBUG {
    //        show_message("hi");
    //    }
    }
    
    show_message(current_time - t);
    And this code to compare vriable speed:
    Code:
    var t = current_time;
    var debug = false;
    
    repeat 100000000 {
        if debug {
            show_message("hi");
        }
    }
    
    show_message(current_time - t);
    The results when I tested this on the windows target for GM:S 1.4 are:
    Code:
    MACRO (Windows):
    4827
    4811
    4779
    4805
    
    COMMENTED (Windows):
    4825
    4785
    4786
    4814
    
    VARIABLE (Windows):
    8067
    8149
    8120
    8005
    I conclude that if-statements with a boolean constant as condition are indeed removed entirely in the end result of the GM:S 1.4 compilation for the windows target.

    PS: Was it this comment you read?
    https://forum.yoyogames.com/index.p...-and-i-have-some-questions.49622/#post-304433
     
    Paskaler likes this.
  3. Paskaler

    Paskaler Member

    Joined:
    Jul 4, 2016
    Posts:
    315
    @jo-thijs, thank you for such a comprehensive answer! And yes, that was the post I was referring to.
     
  4. Paskaler

    Paskaler Member

    Joined:
    Jul 4, 2016
    Posts:
    315
    Sorry for reviving this thread, but, in case anyone stumbles upon this thread looking for the same thing:
    Version 1.99.344 16/01/2015 contains the following notes in it:

    Notes.PNG
     

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