• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

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 64
Joined
Jan 18, 2005
Messages
27,206
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