• 💀 Happy Halloween! 💀 It's time to vote for the best terrain! Check out the entries to Hive's HD Terrain Contest #2 - Vampire Folklore.❗️Poll closes on November 14, 2023. 🔗Click here to cast your vote!
  • 🏆 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!
  • 🏆 HD Level Design Contest #1 is OPEN! Contestants must create a maze with at least one entry point, and at least one exit point. The map should be made in HD mode, and should not be openable in SD. Only custom models from Hive's HD model and texture sections are allowed. The only exceptions are DNC models and omnilights. This is mainly a visual and design oriented contest, not technical. The UI and video walkthrough rules are there to give everyone an equal shot at victory by standardizing how viewers see the terrain. 🔗Click here to enter!

Which Function is Faster?

Not open for further replies.
Level 7
Aug 13, 2007
Which is faster?

My script:
  • 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;...
unit lv_u;
unit lv_u2;
point lv_pt = UnitGetPosition(lp_unit);
point lv_pt2;
fixed lv_distance;
fixed lv_distance2 = 10000.0;
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;
return lv_u2;

UnitGroupClosestToPoint(Unit Group, Point);

Dr Super Good

Spell Reviewer
Level 63
Jan 18, 2005
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.
Not open for further replies.