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

Constants

Status
Not open for further replies.
I didn't say integer vs boolean, but I guess I wasn't really that clear sorry

const int vs int
const bool vs bool

JASS:
scope Benchmark initializer Init

    globals
        private constant integer ITERATIONS = 8191
        private trigger t = CreateTrigger()
        private integer Int = 0
        private constant integer CONST_INT = 0
    endglobals
    
    private function Actions takes nothing returns nothing
        local integer curLoop
        local integer sw      
        local real array result
        
        call DisableTrigger(t)
        call BJDebugMsg("\n\n") 
        
        // TEST 1
        set curLoop = 0
        set sw = StopWatchCreate()
        loop
            exitwhen curLoop == ITERATIONS
            if CONST_INT == 0 then
            endif
            set curLoop = curLoop + 1
        endloop
        set result[0] = StopWatchMark(sw)
        call StopWatchDestroy(sw)
        
        call BJDebugMsg("Constant: " + I2S(curLoop) +" iterations took " + R2S(result[0]))
        call PolledWait(0.1)
        
        // TEST 2
        set curLoop = 0
        set sw = StopWatchCreate()
        loop
            exitwhen curLoop == ITERATIONS
            if Int == 0 then
            endif
            set curLoop = curLoop + 1
        endloop
        set result[1] = StopWatchMark(sw)
        call StopWatchDestroy(sw)
        
        call BJDebugMsg("Regular: " + I2S(curLoop) +" iterations took " + R2S(result[1]))
        
        if (result[0] < result[1]) then
            set result[2] = 100 - (result[0]/result[1] * 100)
            call BJDebugMsg("Test #1 was " + I2S(R2I(result[2])) + "% faster than Test #2")
        else
            set result[2] = 100 - (result[1]/result[0] * 100)
            call BJDebugMsg("Test #1 was " + I2S(R2I(result[2])) + "% slower than Test #2")
        endif
        
        call EnableTrigger(t)
    endfunction

    //===========================================================================
    private function Init takes nothing returns nothing
        call TriggerRegisterPlayerEvent(t, Player(0), EVENT_PLAYER_END_CINEMATIC)
        call TriggerAddAction(t, function Actions)
    endfunction

endscope


with the tests swapped the results are the same
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I never thought people here that do real programming would forget difference between bits and bytes ...
Wc3 is most likely made in C++, which has bool type, which is of size 1 byte(8 bits), while int in C++ is 4 or 8 bytes, depending on architecture(x86 vs x64) which is 32 vs 64 bits.

Both of those types are 4 bytes or bigger

going back to the speed: That may very well be because of the length of variable names also drops speed, to unknown reason but most likely because of the way Jass compiles(JIT compilation to bytecode)

Try dropping the name length of constant int into the same as the non constant one and run it again

Also Mag is claiming that every 4th character adds additional overhead to speed

Also no type can be of less size than 1 byte(8 bits), because you can also only reference individual bytes in memory, and also afaik windows adds padding to all types to make it one word long(4 bytes), at least thats what Ive heared
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Same here, but let's go more off-topic, in french :

bit = bit
byte = octet
And the prononcation of bit and byte is just the same (if we would read it as a french word)

EDIT : Nervemind, silly me, indeed most of time 1 byte = 8 bits = 1 octet, and not 4 bits.
And i've just learned that one byte is commonly used a synonym of an octet, which is apparently also used in english, simply because most of time 1 byte = 8 bits, but that's not an absolute truth :
http://en.wikipedia.org/wiki/Octet_%28computing%29
 
Last edited:
Status
Not open for further replies.
Top