• 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.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

Which Function is Faster?

Status
Not open for further replies.
Which is faster?


My script:
UnitGetNearest
  • Unit Get Nearest
    • Options: Action
    • Return Type: Unit
    • Parameters
      • Unit = No Unit <Unit>
      • Group = (Empty unit group) <Unit Group>
    • Grammar Text: Unit Get Nearest(Unit, Group)
    • Hint Text: Makes the units seek out enemy units and attack them.
    • Custom Script Code
    • Local Variables
    • Actions
      • General - Custom Script: unit lv_u;...
JASS:
unit lv_u;
unit lv_u2;
point lv_pt = UnitGetPosition(lp_unit);
point lv_pt2;
fixed lv_distance;
fixed lv_distance2 = 10000.0;
UnitGroupLoopBegin(lp_group);
while (!UnitGroupLoopDone()) {
    lv_u  = UnitGroupLoopCurrent();
    lv_pt2 = UnitGetPosition(lv_u);
    lv_distance = DistanceBetweenPoints(lv_pt, lv_pt2);
    if (lv_distance < lv_distance2) {
        lv_distance2 = lv_distance;
        lv_u2 = lv_u;
    }
    UnitGroupLoopStep();
}
UnitGroupLoopEnd();
return lv_u2;
OR

JASS:
UnitGroupClosestToPoint(Unit Group, Point);
 

Dr Super Good

Spell Reviewer
Level 65
Joined
Jan 18, 2005
Messages
27,296
UnitGroupClosestToPoint(Unit Group, Point);
This should be faster as it is a native function thus all its mechanisims are probably highly optimized (more so that any galaxy script can be).

Remember that galaxy opperates via a virtual machine which interpretes instructions at runtime. Although this is a lot faster than how JASS opperated in WC3 which was a purly interpreted language, it still is slower than nativly run code (which UnitGroupClosestToPoint should use). It might also use more advanced algorthims with a better than O(n) complexity.
 
Status
Not open for further replies.
Top