HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Compiling speed...

05-26-2006, 10:44 AM#1
Sharingan
Is there even a difference in compiling speed between the following?
1: To do the oldschool comparison "If then...else...endif"
or
2: To If then...return endif, and continue writing the the other condition?
example:
Collapse JASS:
If (a==1) then
    set b = 1
    return
endif
set b = 2

or

Collapse JASS:
If (a==1) then
    set b = 1
else
    set b = 2
endif
Could it be possible that it depends on how long the text after the second action(set b = 2)is?
05-26-2006, 11:58 AM#2
iNfraNe
It would seem to me that example 2 is faster since the code can completely ignore the else part, in example 1 the return would take up some time.
05-26-2006, 12:15 PM#3
Sharingan
Shit...
Not like i don't trust you, but I need to varify this...anyone else knows it for sure?
*don't want to rewrite 10 billion lines*
05-26-2006, 12:29 PM#4
Captain Griffen
To be honest, I can't see it being a significant difference. Though, of course, that is merely in the example, so it may be different for your actualy code (the example makes no sense, as it doesn't do anything).
05-26-2006, 12:55 PM#5
Sharingan
Examples are not mean to make any sense ...
My actual code is just a "varied" version this example, just far longer, like
Collapse JASS:
If (a!=1) then
    set b = 1
    call blabla_1 (blah, blah)
    call blabla_2 (blah, blah)
    call blabla_3 (blah, blah)
    call blabla_4 (blah, blah)
    call blabla_5 (blah, blah)
    if (c!=1) then
        call blabla_6 (blah, blah)
        call blabla_7 (blah, blah)
    else 
        call blabla_8 (blah, blah)
    endif
else
    set b = 2
    call blabla_9 (blah, blah)
endif
I thought, since there are so many "exiting conditions", i might as well as let it exit a bit earlier, like:
Collapse JASS:
If (a==1) then
    set b = 2
    call blabla9 (blah, blah)
    return
endif
set b = 1
call blabla_1 (blah, blah)
call blabla_2 (blah, blah)
call blabla_3 (blah, blah)
call blabla_4 (blah, blah)
call blabla_5 (blah, blah)
if (c==1) then
    call blabla_8 (blah, blah)
    return
endif
call blabla_6 (blah, blah)
call blabla_7 (blah, blah)
05-26-2006, 01:03 PM#6
Captain Griffen
The return actually makes a lot of difference in the example. Having something with a reasonable approximation of what you are asking is most helpful.
05-26-2006, 01:05 PM#7
Sharingan
Hmm, I wanted to know which version of the two is faster...........
And I don't think the result does differ
05-26-2006, 02:14 PM#8
Vexorian
If there is any it won't be noticeable. Compiling happens before even showing the loading bar
05-26-2006, 02:27 PM#9
Sharingan
Hmm, may be I am using the wrong word...
Are you telling me that "compiling" of a trigger with an event only occurs before the game even started?
05-26-2006, 04:39 PM#10
Rising_Dusk
Compiling...
To translate (a program) into machine language.

Basically what Vex is saying is that the map compiles quite awhile before the map has a chance to do anything.

And the speed question really relates to what the 'blahblah's do.
If they are long and complex codes, of course running them no matter what even when unnecessary will take more time than the other way.
However, if they're just... Natives... It won't make any noticeable difference.
05-26-2006, 06:57 PM#11
Sharingan
Hmm, the thing is, they don't run if there is a return before or not?
05-26-2006, 07:44 PM#12
Rising_Dusk
If you return, it will exit the entire function you're currently in.
That means whatever you were doing in that function just ended, whereever you shoved the return.

Collapse JASS:
function IEatDeadPeople takes nothing returns nothing
    local unit u = udg_OmgImNotARealUnit
    
    call GoGoReallyLongFunctionOne(u)
    if (c==1) then
        call GoGoReallyLongFunctionTwo(u)    //In this case, if c == 1 the two
        return                               //functions black and white will
    endif                                    //never execute, and this function
    call Black(u)                            //is over, period.
    call White(u)
endfunction
05-26-2006, 08:42 PM#13
Sharingan
I know... my question was just wether returning would be faster/slower than If...elses
Collapse JASS:
function IEatDeadPeople takes nothing returns nothing
    local unit u = udg_OmgImNotARealUnit    
    call GoGoReallyLongFunctionOne(u)
    if (c!=1) then
        call Black(u)                           
        call White(u)
    else
        call GoGoReallyLongFunctionTwo(u)                       
    endif                   
endfunction
05-26-2006, 09:06 PM#14
BDSM
Not near a comp with WE on it, but perhaps you could do a comparison yourself using a loop. Do half being true and half being false (so that both paths get used equally). Just a thought.
05-26-2006, 10:46 PM#15
weaaddar
Its really not a big deal.