wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Warcraft III Modding > Developer's Corner > Triggers & Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 08-24-2009, 05:30 PM   #1
marshall
User
 
Join Date: Aug 2003
Posts: 104

marshall has little to show at this moment (1)

Question Most effienct way of referencing a unit = ?

I want my map to be as efficient as possible in the basic code (not worrying about systems here, just plain Jass). I've searched around for tips on this but am not completely sure what the pros/cons are of the following snippets of code. Would someone mind pointing out the pros/cons of each of the following in terms of efficiency? Thanks.

Method A
Collapse JASS:
set udg_MyUnitArray[94] = GetTriggerUnit()
call PauseUnit(udg_MyUnitArray[94], true)
call IssueImmediateOrder(udg_MyUnitArray[94], "stop")
call PauseUnit(udg_MyUnitArray[iDynamic], false)

Method B
Collapse JASS:
local unit uTemp = GetTriggerUnit()
set udg_MyUnitArray[94] = uTemp
call PauseUnit(uTemp, true)
call IssueImmediateOrder(uTemp, "stop")
call PauseUnit(uTemp, false)
set uTemp = null

Method C
Collapse JASS:
set udg_MyUnitArray[94] = GetTriggerUnit()
call PauseUnit(GetTriggerUnit(), true)
call IssueImmediateOrder(GetTriggerUnit(), "stop")
call PauseUnit(GetTriggerUnit(), false)

Last edited by marshall : 08-24-2009 at 05:30 PM.
marshall is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 08-24-2009, 05:34 PM   #2
Vulcano
User
 
Join Date: Jul 2009
Posts: 22

Vulcano has little to show at this moment (0)

Default

Collapse JASS:
call PauseUnit(GetTriggerUnit(), true)
call IssueImmediateOrder(GetTriggerUnit(), "stop")
call PauseUnit(GetTriggerUnit(), false)
method A if this isn't ok for you
Vulcano is offline   Reply With Quote
Old 08-24-2009, 05:35 PM   #3
Rising_Dusk
Obscurity, the Art


Projects Director
Project Leader: OD
 
Join Date: Feb 2006
Posts: 9,729

Submissions (27)

Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)Rising_Dusk has a reputation beyond repute (1192)

Hero Contest #3 - 1st PlaceApproved Map: Desert of ExileApproved Map: Advent of the ZenithHero Contest #2 - 1st PlaceHero Contest - Third place>

Send a message via AIM to Rising_Dusk Send a message via MSN to Rising_Dusk
Default

Method B results in the cleanest code, and the speed differences between A, B, and C are negligible. Thus I would recommend using method B.
Collapse JASS:
function MyFunc takes nothing returns nothing
    local unit u = GetTriggerUnit()

    call PauseUnit(u, true)
    call IssueImmediateOrder(u, "stop")
    call PauseUnit(u, false)

    set u = null
endfunction
__________________
Rising_Dusk is offline   Reply With Quote
Old 08-24-2009, 05:36 PM   #4
Alevice
It feels good
 
Alevice's Avatar
 
Join Date: Mar 2006
Posts: 1,305

Alevice is a jewel in the rough (190)Alevice is a jewel in the rough (190)Alevice is a jewel in the rough (190)

Default

method A has to do an array lookup. method B consumes an extra vraible. and method c has to make loads of function calls. the least of the evils is method b.
__________________
_-|-_

Alevice.jones is SC2 Beta, losers.

Check out my never updated deviantart gallery!!

Kalimdor Raiders (Race Contest #1) Pastebin Page
Cavern Crawlers (Race Contest #2) Pastebin Page
Airship Race Motherfuckers!
Quote:
Originally Posted by http://ajaxian.com/archives/would-you-like-a-_-with-that-new-library-gives-js-what-it-should-have#comment-276203
- Dont solve problems that dont exist.
- Improve the wheel, dont reinvent it.
- Port the wheel if it doesnt exist in your environment.
- Integrate the wheel into your project.
- Make sure you can replace your wooden wheel for a rubber one if someone else invents it.
Alevice is offline   Reply With Quote
Old 08-24-2009, 05:38 PM   #5
marshall
User
 
Join Date: Aug 2003
Posts: 104

marshall has little to show at this moment (1)

Default

Thanks guys that's most helpful. I didn't mention that I need the array elsewhere so, given that I have to have the array set anyway, would that make A better than B?

Last edited by marshall : 08-24-2009 at 05:40 PM.
marshall is offline   Reply With Quote
Old 08-24-2009, 10:45 PM   #6
Zerzax
Zerzy
 
Zerzax's Avatar
 
Join Date: Mar 2008
Posts: 708

Submissions (2)

Zerzax is a jewel in the rough (192)Zerzax is a jewel in the rough (192)Zerzax is a jewel in the rough (192)

2008 Spell olympics - Fire - SilverSpell Making Session 13 WinnerSpell Making Session 12 Winner

Send a message via AIM to Zerzax Send a message via MSN to Zerzax
Default

Not really, B is still better because of organization while A requires array lookup. I think everyone already factored in the need to set the unit as part of the array ;)
__________________
Some Quotes of Worthy Wisdom:

1. Die - D2 Barbarian
2. Time to Die - D2 Barbarian
3. Too Much Baggage! - D1 Warrior
4. I Gotta Pawn Some of This Stuff! - D1 Warrior

Last edited by Zerzax : 08-24-2009 at 10:49 PM.
Zerzax is offline   Reply With Quote
Old 08-24-2009, 10:53 PM   #7
Earth-Fury
Two Blue
 
Earth-Fury's Avatar
 
Join Date: Mar 2003
Posts: 2,179

Submissions (7)

Earth-Fury is just really nice (343)Earth-Fury is just really nice (343)Earth-Fury is just really nice (343)Earth-Fury is just really nice (343)

Send a message via MSN to Earth-Fury
Default

Quote:
Originally Posted by marshall
Thanks guys that's most helpful. I didn't mention that I need the array elsewhere so, given that I have to have the array set anyway, would that make A better than B?

The difference between A and B would amount to the difference in the weight of two coins of the same denomination selected at random.

The secret to truly fast JASS code: reduce function calls to a minimum. The only places where Truly Fast JASS™ will make any kind of noticeable difference will be in iterative or recursive shit which recurses/iterates a large number of times. Trying to optimize a function that's called maybe once every 5 seconds will sooner drive you insane then it will actually make any kind of measurable difference.
__________________
Useful Links:
My Resources:
Good Resources:
Search
Tutorials
Ability Guide

UnitMaxState
BonusMod

AutoIndex
ARGB
TimerUtils

Earth-Fury is offline   Reply With Quote
Old 08-24-2009, 11:37 PM   #8
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

This thread is so 2006.

Like people have already pointed out, the speed difference between the methods is absurdly small, practically nonexistant, so in this case readability definitely trumps efficiency.
__________________
Anitarf is offline   Reply With Quote
Old 08-25-2009, 05:26 PM   #9
marshall
User
 
Join Date: Aug 2003
Posts: 104

marshall has little to show at this moment (1)

Default

Thank you all, really cleared things up for me :)
And apologies if this was already well known stuff!
marshall is offline   Reply With Quote
Old 08-25-2009, 08:04 PM   #10
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

Quote:
Originally Posted by marshall
And apologies if this was already well known stuff!
It's not that it's well known, it's just that people have learned not to care about it. I mean, sure, we sometimes give people a hard time about petty efficiency improvements in the submission section but that's usually only the case when we don't like their spell in general, not because we would think having one less local declaration will dramatically improve the speed of the spell.
__________________
Anitarf is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 10:36 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services