• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[General] Which of these two short triggers is more efficient and faster?

Status
Not open for further replies.
Level 11
Joined
Oct 11, 2012
Messages
711
JASS:
function a takes nothing returns nothing
    return 1
endfunction

function b takes nothing returns nothing
    return 2
endfunction

function c takes nothing returns nothing
    return 3
endfunction

function Actions takes nothing returns nothing
    if a then
        ....
    endif
    if b then
        ...
    endif
    if c then
        ...
    endif
endfunction

or

JASS:
function Actions takes nothing returns nothing
    if 1 then
        ....
    endif
    if 2 then
        ...
    endif
    if 3 then
        ...
    endif
endfunction

They have the same outcome, I just wanna know which one is better in terms of efficiency and speed. Thanks guys.
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
The first example is invalid, the functions don't return anything.
JASS:
function a takes nothing returns integer
    return 1
endfunction

function b takes nothing returns integer
    return 2
endfunction

function c takes nothing returns integer
    return 3
endfunction

Poke is right.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
neither would parse, the variables aren't evaluated to a boolean.

technically the 2nd is faster because your sparing a function call but it would be picked up by vexorian's optimizer anyway so it doesn't matter
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
you all forget that first way is inlined, so they are equivalent

vexorian's doesnt auto-inline last i checked. (i threw a pjass error next to a line of code that shouldve been inlined and it wasnt) (and thats what i was saying anyway)

e/ You know whats funny? It does, but it only inlines one function, not two+..
JASS:
        static method addButton takes integer heroIndex, integer buttonId, integer x, integer y returns nothing
            set tree[getLocation(x,y)][getIndex(1, heroIndex)] = buttonId
        endmethod
JASS:
        function s__VJassTalentTree_addButton takes integer heroIndex,integer buttonId,integer x,integer y returns nothing
            call SaveInteger(Table___ht, (((fuuulibrary___tree) + (fuuulibrary___getLocation(x , y)))), (((1 ) + ( ( heroIndex) * ( fuuulibrary___NUM_OF_DATA + 1 ) ))), ( buttonId)) // INLINED!!
        endfunction

it inlined the getIndex call (1 + heroIndex * numofData+1) but not getLocation(x,y)

JASS:
    private function getIndex takes integer data, integer heroIndex returns integer
        return data + (heroIndex * (NUM_OF_DATA + 1))
    endfunction
    private function getLocation takes integer x, integer y returns integer
        return (WIDTH*(y))+x
    endfunction

yes, they throw the same parse error.

Apparently Arhowk is the only one here who knows jass... +rep :p

:p
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
Script optimization

Since version 0.9.A.0 script optimization is available in jasshelper, it is currently enabled by default, in order to disable optimization you can either enable debug mode or use the --nooptimize argument (jasshelper.exe), newgen should get a menu entry for toggling this option added soon.

At the moment the only available optimization is function inlining. More methods shall be added later including some improved versions of some of wc3mapoptimizer's options.

http://www.wc3c.net/vexorian/jasshelpermanual.html
 
Status
Not open for further replies.
Top