| 01-07-2009, 09:47 PM | #1 |
if we need to remove GetTriggerUnit(), do we really need for speed freak to check if the unit is in the group before it, like that JASS:if IsUnitInGroup(GetTriggerUnit(),<group>) then call GroupRemoveUnit(<group>,GetTriggerUnit()) endif or can we do simply that with the same speed, or maybe faster ? JASS:call GroupRemoveUnit(<group>,GetTriggerUnit()) EDIT : Ofc, if we don't need to know that the unit was on the group or not. |
| 01-08-2009, 12:25 AM | #2 |
You'll probably know whether or not the unit is in the group anyway. You should, at least. It's totally based on context, tell more of what your script is trying to do. |
| 01-08-2009, 03:29 AM | #3 |
You dont need any checks for this. Just remove no errors will come. |
| 01-08-2009, 03:31 PM | #4 | |
Quote:
@ Diod : Yes i know that no error will come, but in fact my question is for speed freak only. IsUnitIsGroup vs GroupRemoveUnit. |
| 01-08-2009, 04:15 PM | #5 |
For group check is near instant, but if+else+then slow. Sadly there is no way to build if+else+then without if no jumps around same function lines allow. Ah jump if equal + section markings for jass == divine power. |
| 01-08-2009, 04:16 PM | #6 |
GroupRemoveUnit would be faster, because IsUnitInGroup would require using conditionals in any application. |
| 01-08-2009, 04:53 PM | #7 | |
Quote:
So if IsUnitInGroup is faster than GroupRemoveUnit, when the unit is not in the group, then i will use both, like i've said in the first post of this thread. Could someone benchmark plz ? Because I can't use japi, thx. |
| 01-08-2009, 05:18 PM | #8 |
if else then is much more slower then any native. benchmark will show it. |
| 01-08-2009, 05:27 PM | #9 | |
Quote:
ok but just to know, how many times ? |
| 01-08-2009, 06:02 PM | #10 | ||||||||
JASS:scope Test initializer Init globals private timer t = CreateTimer() private group g = CreateGroup() private unit u private integer i = 0 endglobals function Bench takes nothing returns nothing local integer sw = StopWatchCreate() //Test 1 & 2: if IsUnitInGroup(u,g) then call GroupRemoveUnit(g,u) endif // //Test 3 & 4: call GroupRemoveUnit(g,u) // call DebugPrint(R2S(StopWatchMark(sw)*1000000)) call StopWatchDestroy(sw) //Test 1 & 3: call GroupAddUnit(g,u) // set i = i+1 if i > 50000 then call PauseTimer(t) call BJDebugMsg("Done") endif endfunction private function Init takes nothing returns nothing call DebugPrint("=============================") set u = CreateUnit(Player(0), 'hpea', 0., 0., 0.) //Test 1 & 3: call GroupAddUnit(g,u) // call TimerStart(t, 0., true, function Bench) endfunction endscope war3err off, done three times, time for null-test subtracted, etc. Times in microseconds:
|
| 01-08-2009, 06:25 PM | #11 |
Thx, is it the same if the unit is not in the group, i dunno how groups are handle, but i guess it should take more time, no ? |
| 01-08-2009, 06:41 PM | #12 |
Tests 2 & 4 don't have the unit in the group, tests 1 & 2 do. Otherwise tests 1 and 2 are the same, and tests 3 and 4 are the same. |
| 01-08-2009, 06:57 PM | #13 | ||
Quote:
You want mean that ? Quote:
|
| 01-08-2009, 06:59 PM | #14 |
opps, yes. |
| 01-08-2009, 07:06 PM | #15 |
Thx for testing. |
