• 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.

Integer comparison question

Status
Not open for further replies.
Level 5
Joined
Sep 19, 2006
Messages
152
Consider the following 2 fictitious triggers:

JASS:
set a = 1
loop
exitwhen a == 11
call (blah, blah, blah)
set a = a + 1
endloop

and

JASS:
set a = 1
loop
exitwhen a > 10
call (blah, blah, blah)
set a = a + 1
endloop

Is there any resource-difference between determining if "a" is equal to 11 and determining if "a" is greater than 10?
 
">" is slightly more optimal just because JASS is an interpreted language making each character an index in the war3map.j string so more characters takes an infinitesimal longer amount of time to process.

In a normal programming language, "==" is faster than ">".

However, in either case, the efficiency is not even worth thinking about. I don't lose any sleep at night if I use ">" instead of "==" or the other way around.
 
Level 5
Joined
Sep 19, 2006
Messages
152
">" is slightly more optimal just because JASS is an interpreted language making each character an index in the war3map.j string so more characters takes an infinitesimal longer amount of time to process.

In a normal programming language, "==" is faster than ">".

However, in either case, the efficiency is not even worth thinking about. I don't lose any sleep at night if I use ">" instead of "==" or the other way around.

Cool. Thank you.
 
From anything I've read concerning it, in a bytecode programming language like C where non-zero is true and 0 is false, my understanding is the CPU is decoding the inequality operator as "left minus right", the equality operator as "not (left minus right)", and the less_than operator doesn't seem to have a direct boolean assignment (though I could be wrong).

Either way it doesn't matter AT ALL. The speed difference is utterly pointless.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
In a normal programming language, "==" is faster than ">".
Incorrect.

It depends highly on the instruction set but most of them have many dedicated instructions to do this which atmost vary by 1 clock cycle. As processors are pipe-lined this makes no difference at all (they execute about 1 instruction a clock edge anyway).

Most like x86 (what WC3 runs on) have a single dedicated comparision instruction (CMP) which performs all comparisions at once setting internal flags based on the result. You then specify how the results get interpreted using the opperator (all comparisions are done equally fast). Any other more specific comparision instructions will probably run slower due to designers only focusing on performance for a reduced instruction set for better pipe-lining.

The case of speed differences in JASS would be down to how it works internally as unlike normal programming, JASS is run in some kind of interpreter/virtual machine so does not translate directly into machine code.
 
Status
Not open for further replies.
Top