HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

using an array variable vs a not array variable

08-08-2008, 09:01 AM#1
Troll-Brain
I know using an array variable is slower than using a not array variable.
But how much ?

for example :

Collapse JASS:
globals
   integer array Ia
   integer I
endglobals

function test takes integer i returns nothing
   set Ia[i]=5
   call BJDebugMsg(I2S(Ia[i]))
   call BJDebugMsg(I2S(Ia[i]+1))
   call BJDebugMsg(I2S(Ia[i]+2))
   set Ia[i]=0
endfunction

Yes i know this example is useless and not safe, that's not the question.

Should it be faster if i do that :

Collapse JASS:
function test takes integer i returns nothing
   set Ia[i]=5
   set I=Ia[i]
   call BJDebugMsg(I2S(I))
   call BJDebugMsg(I2S(I+1))
   call BJDebugMsg(I2S(I+2))
   set Ia[i]=0
endfunction
08-09-2008, 05:31 AM#2
chobibo
IMO, yes, since it doesn't require an array look-up every time it is used.
08-09-2008, 10:09 AM#3
Anitarf
In this case (and most other cases) it doesn't matter at all, compared to I2S+BJDebugMsg the array lookup costs almost nothing.
08-09-2008, 10:18 AM#4
Troll-Brain
Quote:
Originally Posted by Anitarf
In this case (and most other cases) it doesn't matter at all, compared to I2S+BJDebugMsg the array lookup costs almost nothing.
I said that's a stupid example, don't care about the functions ...
Ok, but it's still faster ?
I mean if i use in a hudge loop or a short periodic timer should i use a non array variable ?

In general how many used of an array variable justify the using of an array non variable ?
(2,3 , more ?)

EDIT

I ask that because i can't use japi.

I've uncomment these lines on the ongameload.lua:
loaddll("bin\\japi.dll")
loaddll("bin\\nativepack.dll")

I can save a map with japi natives but when i test it's back to the warcraft menu.
08-09-2008, 11:12 AM#5
Toadcop
~(1.5-2) times

locals are faster but it takes decent allocation time.
08-09-2008, 11:13 AM#6
darkwulfv
The deviation is probably so minor that nobody will ever make a big deal out of it.
08-10-2008, 01:46 AM#7
Ammorth
Quote:
Originally Posted by Troll-Brain
I can save a map with japi natives but when i test it's back to the warcraft menu.
don't call the init custom natives functions. stop watch still works without it and I don't know if it does anything to begin with.
08-11-2008, 08:07 AM#8
Troll-Brain
Quote:
Originally Posted by Ammorth
don't call the init custom natives functions. stop watch still works without it and I don't know if it does anything to begin with.
I tried, it's still the same :(
08-11-2008, 01:59 PM#9
Anitarf
When I recently asked around what was faster, allocating a handle or allocating a struct (a difference much more significant than what you're asking), PipeDream encouraged me not to care. I extend the same suggestion to you.
08-11-2008, 03:11 PM#10
Troll-Brain
Quote:
Originally Posted by Anitarf
When I recently asked around what was faster, allocating a handle or allocating a struct (a difference much more significant than what you're asking), PipeDream encouraged me not to care. I extend the same suggestion to you.
That's not the question but thx for the tip.