Quick Speed Fact

Nestharus

o-o
Reaction score
84
Quick Speed Facts

All results are averaged!

NEWS
Declaring a local variable is 40% to 70% faster than setting a global variable!!

Modifier results to show percent-
JASS:
do {
            printf(testMessage[iterator] + R2SW(mark[iterator], 0, 6))
            if iterator-1 > 0 {
                if mark[iterator-1] > mark[iterator] {
                    printf("Speed Difference: " + R2SW(((1000*mark[iterator-1])/(1000*mark[iterator]))*100-100, 0, 6) + "\% faster")
                }
                else {
                    printf("Speed Difference: " + R2SW(((1000*mark[iterator])/(1000*mark[iterator-1]))*100-100, 0, 6) + "\% slower")
                }
                printf(" ")
            }
            else {printf(" ")}
        } whilenot --iterator == 0

Variable definition for 100
JASS:
define
    {
        private VARIABLES(theType, theValue) = {
            theType i1 theValue
            theType i2 theValue
            theType i3 theValue
            theType i4 theValue
            theType i5 theValue
            theType i6 theValue
            theType i7 theValue
            theType i8 theValue
            theType i9 theValue
            theType i10 theValue
            theType i11 theValue
            theType i12 theValue
            theType i13 theValue
            theType i14 theValue
            theType i15 theValue
            theType i16 theValue
            theType i17 theValue
            theType i18 theValue
            theType i19 theValue
            theType i20 theValue
            theType i21 theValue
            theType i22 theValue
            theType i23 theValue
            theType i24 theValue
            theType i25 theValue
            theType i26 theValue
            theType i27 theValue
            theType i28 theValue
            theType i29 theValue
            theType i30 theValue
            theType i31 theValue
            theType i32 theValue
            theType i33 theValue
            theType i34 theValue
            theType i35 theValue
            theType i36 theValue
            theType i37 theValue
            theType i38 theValue
            theType i39 theValue
            theType i40 theValue
            theType i41 theValue
            theType i42 theValue
            theType i43 theValue
            theType i44 theValue
            theType i45 theValue
            theType i46 theValue
            theType i47 theValue
            theType i48 theValue
            theType i49 theValue
            theType i50 theValue
            theType i51 theValue
            theType i52 theValue
            theType i53 theValue
            theType i54 theValue
            theType i55 theValue
            theType i56 theValue
            theType i57 theValue
            theType i58 theValue
            theType i59 theValue
            theType i60 theValue
            theType i61 theValue
            theType i62 theValue
            theType i63 theValue
            theType i64 theValue
            theType i65 theValue
            theType i66 theValue
            theType i67 theValue
            theType i68 theValue
            theType i69 theValue
            theType i70 theValue
            theType i71 theValue
            theType i72 theValue
            theType i73 theValue
            theType i74 theValue
            theType i75 theValue
            theType i76 theValue
            theType i77 theValue
            theType i78 theValue
            theType i79 theValue
            theType i80 theValue
            theType i81 theValue
            theType i82 theValue
            theType i83 theValue
            theType i84 theValue
            theType i85 theValue
            theType i86 theValue
            theType i87 theValue
            theType i88 theValue
            theType i89 theValue
            theType i90 theValue
            theType i91 theValue
            theType i92 theValue
            theType i93 theValue
            theType i94 theValue
            theType i95 theValue
            theType i96 theValue
            theType i97 theValue
            theType i98 theValue
            theType i99 theValue
            theType i100 theValue
        }
    }

Never use a basic native conversions when you have a constant variable as the constant variable version is faster. Always try to use wrappers, even if they are arrays, over native conversions.

The array is 33% faster than the convert native
Benchmark Code-
JASS:
include "cj_types.j"
include "cj_typesEx.j"
include "cj_print.j"
include "cj_types_priv.j"  
include "cj_typesEx_priv.j"
include "cj_order.j"  
include "cj_antibj_base.j"

scope Demo initializer Initialization {
    private constant int TESTS = 2
    private constant int LOOPS = 10000
    private trigger privateTrigger = CreateTrigger()
    private event privateEvent = TriggerRegisterTimerEvent(privateTrigger, 0, false)
    private int sw
    private real array mark
    private int testBenchmarkIterator = TESTS
    private int iterator = TESTS
    private timer timerBenchmark = CreateTimer()
    private string array testMessage
    
    //Variables to Test
    private player array playerTest
    private player SET
    
    private void Benchmark1()
    {
        iterator = LOOPS
        testMessage[1] = "Convert Test: "
        sw = StopWatchCreate()
        do {
            //Code to Test
            SET = Player(0)
        } whilenot --iterator == 0
        mark[1] = StopWatchMark(sw)
        StopWatchDestroy(sw)
    }
    
    private void Benchmark2()
    {
        iterator = LOOPS
        testMessage[2] = "Variable Test: "
        sw = StopWatchCreate()
        do {
            //Code to Test
            SET = playerTest[0]
        } whilenot --iterator == 0
        mark[2] = StopWatchMark(sw)
        StopWatchDestroy(sw)
    }
    
    private void TestBenchmarker()
    {
        mark[0] = StopWatchMark(sw)
        call StopWatchDestroy(sw)
        do {
            //printf(SCOPE_PRIVATE + "Benchmark" + I2S(iterator))
            ExecuteFunc(SCOPE_PRIVATE + "Benchmark" + I2S(testBenchmarkIterator))
        } whilenot --testBenchmarkIterator == 0
        iterator = TESTS
        do {
            printf(testMessage[iterator] + R2SW(mark[iterator], 0, 6))
        } whilenot --iterator == 0
    }
    
    private bool TestBenchmark() {
        sw = StopWatchCreate()
        TimerStart(timerBenchmark, 1, false, function TestBenchmarker)
        return false
    }
    
    void Initialization() {
        TriggerAddCondition(privateTrigger, Condition(function TestBenchmark))
        
        //Ini
        playerTest[0] = Player(0)
    }
}

Arrays are 75% faster than hashtables
JASS:
include "cj_types.j"
include "cj_typesEx.j"
include "cj_print.j"
include "cj_types_priv.j"  
include "cj_typesEx_priv.j"
include "cj_order.j"  
include "cj_antibj_base.j"

scope Demo initializer Initialization {
    private constant int TESTS = 2
    private constant int LOOPS = 10000
    private trigger privateTrigger = CreateTrigger()
    private event privateEvent = TriggerRegisterTimerEvent(privateTrigger, 0, false)
    private int sw
    private real array mark
    private int testBenchmarkIterator = TESTS
    private int iterator = TESTS
    private timer timerBenchmark = CreateTimer()
    private string array testMessage
    
    //Variables to Test
    private hashtable hashtableTest = InitHashtable()
    private integer array arrayTest
    private integer SET
    
    private void Benchmark1()
    {
        iterator = LOOPS
        testMessage[1] = "Array Test: "
        sw = StopWatchCreate()
        do {
            //Code to Test
            SET = arrayTest[0]
        } whilenot --iterator == 0
        mark[1] = StopWatchMark(sw)
        StopWatchDestroy(sw)
    }
    
    private void Benchmark2()
    {
        iterator = LOOPS
        testMessage[2] = "Hashtable Test: "
        sw = StopWatchCreate()
        do {
            //Code to Test
            SET = LoadInteger(hashtableTest, 0, 0)
        } whilenot --iterator == 0
        mark[2] = StopWatchMark(sw)
        StopWatchDestroy(sw)
    }
    
    private void TestBenchmarker()
    {
        mark[0] = StopWatchMark(sw)
        call StopWatchDestroy(sw)
        do {
            //printf(SCOPE_PRIVATE + "Benchmark" + I2S(iterator))
            ExecuteFunc(SCOPE_PRIVATE + "Benchmark" + I2S(testBenchmarkIterator))
        } whilenot --testBenchmarkIterator == 0
        iterator = TESTS
        do {
            printf(testMessage[iterator] + R2SW(mark[iterator], 0, 6))
        } whilenot --iterator == 0
    }
    
    private bool TestBenchmark() {
        sw = StopWatchCreate()
        TimerStart(timerBenchmark, 1, false, function TestBenchmarker)
        return false
    }
    
    void Initialization() {
        TriggerAddCondition(privateTrigger, Condition(function TestBenchmark))
        
        //Ini
        arrayTest[0] = 1
        SaveInteger(hashtableTest, 0, 0, 1)
    }
}

Global arrays are 35% faster than local variables
JASS:
include "cj_types.j"
include "cj_typesEx.j"
include "cj_print.j"
include "cj_types_priv.j"  
include "cj_typesEx_priv.j"
include "cj_order.j"  
include "cj_antibj_base.j"

scope Demo initializer Initialization {
    private constant int TESTS = 2
    private constant int LOOPS = 10000
    private trigger privateTrigger = CreateTrigger()
    private event privateEvent = TriggerRegisterTimerEvent(privateTrigger, 0, false)
    private int sw
    private real array mark
    private int testBenchmarkIterator = TESTS
    private int iterator = TESTS
    private timer timerBenchmark = CreateTimer()
    private string array testMessage
    
    //Variables to Test
    private int array variableTest
    private int SET
    
    private void Benchmark1()
    {
        int i = 1
        iterator = LOOPS
        testMessage[1] = "Local Test: "
        sw = StopWatchCreate()
        do {
            //Code to Test
            SET = i
        } whilenot --iterator == 0
        mark[1] = StopWatchMark(sw)
        StopWatchDestroy(sw)
    }
    
    private void Benchmark2()
    {
        iterator = LOOPS
        testMessage[2] = "Array Test: "
        sw = StopWatchCreate()
        do {
            //Code to Test
            SET = variableTest[0]
        } whilenot --iterator == 0
        mark[2] = StopWatchMark(sw)
        StopWatchDestroy(sw)
    }
    
    private void TestBenchmarker()
    {
        mark[0] = StopWatchMark(sw)
        call StopWatchDestroy(sw)
        do {
            //printf(SCOPE_PRIVATE + "Benchmark" + I2S(iterator))
            ExecuteFunc(SCOPE_PRIVATE + "Benchmark" + I2S(testBenchmarkIterator))
        } whilenot --testBenchmarkIterator == 0
        iterator = TESTS
        do {
            printf(testMessage[iterator] + R2SW(mark[iterator], 0, 6))
        } whilenot --iterator == 0
    }
    
    private bool TestBenchmark() {
        sw = StopWatchCreate()
        TimerStart(timerBenchmark, 1, false, function TestBenchmarker)
        return false
    }
    
    void Initialization() {
        TriggerAddCondition(privateTrigger, Condition(function TestBenchmark))
        
        //Ini
        variableTest[0] = 1
    }
}

Global variables are anywhere from 10% slower to 10% faster than a global array
JASS:
include "cj_types.j"
include "cj_typesEx.j"
include "cj_print.j"
include "cj_types_priv.j"  
include "cj_typesEx_priv.j"
include "cj_order.j"  
include "cj_antibj_base.j"

scope Demo initializer Initialization {
    private constant int TESTS = 2
    private constant int LOOPS = 10000
    private trigger privateTrigger = CreateTrigger()
    private event privateEvent = TriggerRegisterTimerEvent(privateTrigger, 0, false)
    private int sw
    private real array mark
    private int testBenchmarkIterator = TESTS
    private int iterator = TESTS
    private timer timerBenchmark = CreateTimer()
    private string array testMessage
    
    //Variables to Test
    private int array variableTest
    private int variableTest2 = 1
    private int SET
    
    private void Benchmark1()
    {
        iterator = LOOPS
        testMessage[1] = "Global Variable Test: "
        sw = StopWatchCreate()
        do {
            //Code to Test
            SET = variableTest2
        } whilenot --iterator == 0
        mark[1] = StopWatchMark(sw)
        StopWatchDestroy(sw)
    }
    
    private void Benchmark2()
    {
        iterator = LOOPS
        testMessage[2] = "Global Array Test: "
        sw = StopWatchCreate()
        do {
            //Code to Test
            SET = variableTest[0]
        } whilenot --iterator == 0
        mark[2] = StopWatchMark(sw)
        StopWatchDestroy(sw)
    }
    
    private void TestBenchmarker()
    {
        mark[0] = StopWatchMark(sw)
        call StopWatchDestroy(sw)
        do {
            //printf(SCOPE_PRIVATE + "Benchmark" + I2S(iterator))
            ExecuteFunc(SCOPE_PRIVATE + "Benchmark" + I2S(testBenchmarkIterator))
        } whilenot --testBenchmarkIterator == 0
        iterator = TESTS
        do {
            printf(testMessage[iterator] + R2SW(mark[iterator], 0, 6))
        } whilenot --iterator == 0
    }
    
    private bool TestBenchmark() {
        sw = StopWatchCreate()
        TimerStart(timerBenchmark, 1, false, function TestBenchmarker)
        return false
    }
    
    void Initialization() {
        TriggerAddCondition(privateTrigger, Condition(function TestBenchmark))
        
        //Ini
        variableTest[0] = 1
    }
}

local arrays are 7.5% faster than local variables
JASS:
include "cj_types.j"
include "cj_typesEx.j"
include "cj_print.j"
include "cj_types_priv.j"  
include "cj_typesEx_priv.j"
include "cj_order.j"  
include "cj_antibj_base.j"

scope Demo initializer Initialization {
    private constant int TESTS = 2
    private constant int LOOPS = 10000
    private trigger privateTrigger = CreateTrigger()
    private event privateEvent = TriggerRegisterTimerEvent(privateTrigger, 0, false)
    private int sw
    private real array mark
    private int testBenchmarkIterator = TESTS
    private int iterator = TESTS
    private timer timerBenchmark = CreateTimer()
    private string array testMessage
    
    //Variables to Test
    //private int array variableTest
    private int SET
    
    private void Benchmark1()
    {
        int array variableTest2
        variableTest2[0] = 1
        iterator = LOOPS
        testMessage[1] = "Local Array Test: "
        sw = StopWatchCreate()
        do {
            //Code to Test
            SET = variableTest2[0]
        } whilenot --iterator == 0
        mark[1] = StopWatchMark(sw)
        StopWatchDestroy(sw)
    }
    
    private void Benchmark2()
    {
        local int variableTest = 1
        iterator = LOOPS
        testMessage[2] = "Local Variable Test: "
        sw = StopWatchCreate()
        do {
            //Code to Test
            SET = variableTest
        } whilenot --iterator == 0
        mark[2] = StopWatchMark(sw)
        StopWatchDestroy(sw)
    }
    
    private void TestBenchmarker()
    {
        mark[0] = StopWatchMark(sw)
        call StopWatchDestroy(sw)
        do {
            //printf(SCOPE_PRIVATE + "Benchmark" + I2S(iterator))
            ExecuteFunc(SCOPE_PRIVATE + "Benchmark" + I2S(testBenchmarkIterator))
        } whilenot --testBenchmarkIterator == 0
        iterator = TESTS
        do {
            printf(testMessage[iterator] + R2SW(mark[iterator], 0, 6))
        } whilenot --iterator == 0
    }
    
    private bool TestBenchmark() {
        sw = StopWatchCreate()
        TimerStart(timerBenchmark, 1, false, function TestBenchmarker)
        return false
    }
    
    void Initialization() {
        TriggerAddCondition(privateTrigger, Condition(function TestBenchmark))
        
        //Ini
    }
}

Constant functions are in fact the same speed as regular functions
JASS:
include "cj_types.j"
include "cj_typesEx.j"
include "cj_print.j"
include "cj_types_priv.j"  
include "cj_typesEx_priv.j"
include "cj_order.j"  
include "cj_antibj_base.j"

scope Demo initializer Initialization {
    private constant int TESTS = 2
    private constant int LOOPS = 10000
    private trigger privateTrigger = CreateTrigger()
    private event privateEvent = TriggerRegisterTimerEvent(privateTrigger, 0, false)
    private int sw
    private real array mark
    private int testBenchmarkIterator = TESTS
    private int iterator = TESTS
    private timer timerBenchmark = CreateTimer()
    private string array testMessage
    
    //Variables to Test
    
    //private integer SET
    
    private constant void Test1() {}
    private void Test2() {}
    
    private void Benchmark1()
    {
        iterator = LOOPS
        testMessage[1] = "Constant Test: "
        sw = StopWatchCreate()
        do {
            //Code to Test
            Test1()
        } whilenot --iterator == 0
        mark[1] = StopWatchMark(sw)
        StopWatchDestroy(sw)
    }
    
    private void Benchmark2()
    {
        iterator = LOOPS
        testMessage[2] = "Function Test: "
        sw = StopWatchCreate()
        do {
            //Code to Test
            Test2()
        } whilenot --iterator == 0
        mark[2] = StopWatchMark(sw)
        StopWatchDestroy(sw)
    }
    
    private void TestBenchmarker()
    {
        mark[0] = StopWatchMark(sw)
        call StopWatchDestroy(sw)
        do {
            //printf(SCOPE_PRIVATE + "Benchmark" + I2S(iterator))
            ExecuteFunc(SCOPE_PRIVATE + "Benchmark" + I2S(testBenchmarkIterator))
        } whilenot --testBenchmarkIterator == 0
        iterator = TESTS
        do {
            printf(testMessage[iterator] + R2SW(mark[iterator], 0, 6))
        } whilenot --iterator == 0
    }
    
    private bool TestBenchmark() {
        sw = StopWatchCreate()
        TimerStart(timerBenchmark, 1, false, function TestBenchmarker)
        return false
    }
    
    void Initialization() {
        TriggerAddCondition(privateTrigger, Condition(function TestBenchmark))
        
        //Ini
    }
}

A global variable containing GetLocalPlayer() is 33% faster than a GetLocalPlayer() call
JASS:
include "cj_types.j"
include "cj_typesEx.j"
include "cj_print.j"
include "cj_types_priv.j"  
include "cj_typesEx_priv.j"
include "cj_order.j"  
include "cj_antibj_base.j"

scope Demo initializer Initialization {
    private constant int TESTS = 2
    private constant int LOOPS = 10000
    private trigger privateTrigger = CreateTrigger()
    private event privateEvent = TriggerRegisterTimerEvent(privateTrigger, 0, false)
    private int sw
    private real array mark
    private int testBenchmarkIterator = TESTS
    private int iterator = TESTS
    private timer timerBenchmark = CreateTimer()
    private string array testMessage
    
    //Variables to Test
    private player localPlayer
    private player SET
    
    private void Benchmark1()
    {
        iterator = LOOPS
        testMessage[1] = "Variable Test: "
        sw = StopWatchCreate()
        do {
            //Code to Test
            SET = localPlayer
        } whilenot --iterator == 0
        mark[1] = StopWatchMark(sw)
        StopWatchDestroy(sw)
    }
    
    private void Benchmark2()
    {
        iterator = LOOPS
        testMessage[2] = "Native Test: "
        sw = StopWatchCreate()
        do {
            //Code to Test
            SET = GetLocalPlayer()
        } whilenot --iterator == 0
        mark[2] = StopWatchMark(sw)
        StopWatchDestroy(sw)
    }
    
    private void TestBenchmarker()
    {
        mark[0] = StopWatchMark(sw)
        call StopWatchDestroy(sw)
        do {
            //printf(SCOPE_PRIVATE + "Benchmark" + I2S(iterator))
            ExecuteFunc(SCOPE_PRIVATE + "Benchmark" + I2S(testBenchmarkIterator))
        } whilenot --testBenchmarkIterator == 0
        iterator = TESTS
        do {
            printf(testMessage[iterator] + R2SW(mark[iterator], 0, 6))
            if iterator-1 > 0 {
                if mark[iterator-1] > mark[iterator] {
                    printf("Speed Difference: " + R2SW(((1000*mark[iterator-1])/(1000*mark[iterator]))*100-100, 0, 6) + "\% faster")
                }
                else {
                    printf("Speed Difference: " + R2SW(((1000*mark[iterator])/(1000*mark[iterator-1]))*100-100, 0, 6) + "\% slower")
                }
                printf(" ")
            }
            else {printf(" ")}
        } whilenot --iterator == 0
    }
    
    private bool TestBenchmark() {
        sw = StopWatchCreate()
        TimerStart(timerBenchmark, 1, false, function TestBenchmarker)
        return false
    }
    
    void Initialization() {
        TriggerAddCondition(privateTrigger, Condition(function TestBenchmark))
        
        //Ini
        localPlayer = GetLocalPlayer()
    }
}

The filterfunc variable and boolexpr variable are the exact same speed! They also both retrieve the Filtered Unit at the same rate : D. It doesn't matter which one you use.
JASS:
include "cj_types.j"
include "cj_typesEx.j"
include "cj_print.j"
include "cj_types_priv.j"  
include "cj_typesEx_priv.j"
include "cj_order.j"  
include "cj_antibj_base.j"

scope Demo initializer Initialization {
    private constant int TESTS = 2
    private constant int LOOPS = 10000
    private trigger privateTrigger = CreateTrigger()
    private event privateEvent = TriggerRegisterTimerEvent(privateTrigger, 0, false)
    private int sw
    private real array mark
    private int testBenchmarkIterator = TESTS
    private int iterator = TESTS
    private timer timerBenchmark = CreateTimer()
    private string array testMessage
    
    //Variables to Test
    private boolexpr boolFilter
    private filterfunc filterFilter
    private group testGroup = CreateGroup()
    
    private bool TestFilter() {return false}
    
    private void Benchmark1()
    {
        iterator = LOOPS
        testMessage[1] = "Boolean Expression Test: "
        sw = StopWatchCreate()
        do {
            //Code to Test
            GroupEnumUnitsOfPlayer(testGroup, Player(0), boolFilter)
        } whilenot --iterator == 0
        mark[1] = StopWatchMark(sw)
        StopWatchDestroy(sw)
    }
    
    private void Benchmark2()
    {
        iterator = LOOPS
        testMessage[2] = "Filter Test: "
        sw = StopWatchCreate()
        do {
            //Code to Test
            GroupEnumUnitsOfPlayer(testGroup, Player(0), filterFilter)
        } whilenot --iterator == 0
        mark[2] = StopWatchMark(sw)
        StopWatchDestroy(sw)
    }
    
    private void TestBenchmarker()
    {
        mark[0] = StopWatchMark(sw)
        call StopWatchDestroy(sw)
        do {
            ExecuteFunc(SCOPE_PRIVATE + "Benchmark" + I2S(testBenchmarkIterator))
        } whilenot --testBenchmarkIterator == 0
        iterator = TESTS
        do {
            printf(testMessage[iterator] + R2SW(mark[iterator], 0, 6))
            if iterator-1 > 0 {
                if mark[iterator-1] > mark[iterator] {
                    printf("Speed Difference: " + R2SW(((1000*mark[iterator-1])/(1000*mark[iterator]))*100-100, 0, 6) + "\% faster")
                }
                else {
                    printf("Speed Difference: " + R2SW(((1000*mark[iterator])/(1000*mark[iterator-1]))*100-100, 0, 6) + "\% slower")
                }
                printf(" ")
            }
            else {printf(" ")}
        } whilenot --iterator == 0
    }
    
    private bool TestBenchmark() {
        sw = StopWatchCreate()
        TimerStart(timerBenchmark, 1, false, function TestBenchmarker)
        return false
    }
    
    void Initialization() {
        TriggerAddCondition(privateTrigger, Condition(function TestBenchmark))
        //Ini
        CreateUnit(Player(0), 'hpea', 0, 0, 270)
        boolFilter = Condition(function TestFilter)
        filterFilter = Filter(function TestFilter)
    }
}

* Setting a local variable vs setting a global variable with a precondition: 100 locals declared and 1 global.
Global is 30% to 60% faster

* Setting a local variable vs setting a global variable with a precondition: 1 locals declared and 100 globals.
Global is 75% faster ???

* Getting from a local variable vs getting from a global variable with a precondition: 100 locals declared and 1 global.
Global is 50% to 65% faster

* Getting from a local variable vs getting from a global variable with a precondition: 1 local declared and 100 globals.
Global is 56% to 70% faster

* The execution time of declaring a local variable compared to setting a global variable with a precondition: 100 locals declared and 1 global.
Globals: 150% faster

* The execution time of declaring a local variable compared to setting a global variable with a precondition: 1 locals declared and 100 global.
Locals: 40% to 70% faster
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Are you kidding me ?!?!?!?!

Do you call this a tutorial ?!

You put 2 sentences there, which I can't seem to get any understanding from, and you call this a tutorial ?

And what is that cJASS code doing there ? :S
 

Trollvottel

never aging title
Reaction score
262
Pls post the speed difference, i guess it is small. Speed is not everything, and nobody knows what you mean if you wirte ConvertSomeStupidThing(3) instead of SENSELESS_STUFF_WITH_CHOCOLATE

Constants are there for making code easier to read.
 

Nestharus

o-o
Reaction score
84
My initial tests were wrong... for some reason... I got bad results ><, no idea why. I set a string array before testing each for the next set of tests and got right results... don't know why setting the string was so important, but... lol, wow so weird

So read the first post again : P

I put this up because there are so many people guessing at which are faster and nobody is doing the benchmarks ^_^. It's a quick speed fact with the benchmark code to prove it =P.
 

Trollvottel

never aging title
Reaction score
262
Kay, i was surprised about the results (variables slower than function calls? o0), but now it is as expected ^^. so i think we can graveyard this (or start to make a list with functions and how fast there are, but i think there are other websites which have those)
 

Nestharus

o-o
Reaction score
84
I'm still adding speed facts, there are some SERIOUSLY surprising results o-o.

Did you know that a local array is faster than a local variable??

But a global variable is faster than a global array o_O
 

Romek

Super Moderator
Reaction score
963
This isn't a tutorial.
GY'd.

Any interesting JASS discoveries go in the JASS forum, not in T&R.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Try to change the orders of the tests, for example first local variables and then local array variables, you could get the opposite result.

Also 10 000 iterations sounds better, especially for setting variables, in fact i guess you could do much more, and be more accurate in results.
 

Jesus4Lyf

Good Idea™
Reaction score
397
Try to change the orders of the tests, for example first local variables and then local array variables, you could get the opposite result.
This.

>Global arrays are in fact faster than local variables
You're funny.

>Pls post the speed difference
This too.

>And what is that cJASS code doing there ? :S
This too.

What's the use if you post cJass code? We can't replicate your tests...

I find in random circumstances that locals are faster. I gave up benchmarking small stuff like that. You'll have a ball, but don't kid yourself. None of it matters a bit.
 

Nestharus

o-o
Reaction score
84
Posted speed differences..

oh yes, and no forum actually has a list of results like this... so it's actually useful to know this stuff ...

Also, 9 times out of 10, the global was faster for me by 25%, heh.

And-
This isn't a tutorial.
GY'd.

Any interesting JASS discoveries go in the JASS forum, not in T&R.

So you are telling me to repost this in the right forum? Don't you normally move things into the right forum rather than tell the person to post again?

Ok, posting again then -.-
 

Nestharus

o-o
Reaction score
84
Yes, made 0 difference.


I guess I'm posting this again, but in the right forum, unless this gets moved.
 

Romek

Super Moderator
Reaction score
963
Are you sure those tests are accurate?
I haven't looked at the code, but I saw this:
> Global variables are anywhere from 10% slower to 10% faster than a global array
Now we know that globals are slawster than global arrays.
 

Nestharus

o-o
Reaction score
84
According to my results with 10,000 iterations and 25 tests... it was too random, anywhere from 10% slower to 10% faster =)

Because it wasn't something like 1-5%, I couldn't say that they were the same speed. 10% says that sometimes the array is faster, and sometimes the global variable is faster. According to the test, it didn't matter what you used o-o.


This test for me was actually the strangest-
local arrays are faster than local variables

The local array was always faster than the local variable, every single time o-o, but the global variable and the global arrays are random with their speeds.


Oh yea Romek, sry for posting this in T&R. I figured that speed facts about JASS would be something of a tutorial, or a factoid, or something like that so I posted it here =).

So you want me to repost in JASS Help or will you move it?

And the tests are averaged. Arrays are actually 68% faster to 81% faster compared to hashtables, but I averaged to 75%.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
So try to make more iterations.
And to be sure you don't reach the limitop, display a text at the end of the test.
 

Nestharus

o-o
Reaction score
84
5000 and 10000 merited the same results, lol.

I can push up to about 11k without hitting op limit ... 10k is pretty darn close to the max I can go with this.

I guess these speed facts don't matter tho, since this is in the graveyard, even though people are constantly asking, is a wrapper faster than a native, or is this faster than that, etc. Apparently the questions of the community mean nothing and should just be left unanswered -.-.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Ok, but admit the results are senseless, or at least weird.
I can't imagine a global array variable is about the same speed or faster (wtf !) than a global not array one.
Same for local array variable VS local not array variable.

Maybe Stopwatch natives aren't enough accurate, dunno.

EDIT :

It is in the graveyard because it's clearly not a tutorial, don't take it so bad/personal.
 

Romek

Super Moderator
Reaction score
963
Moved to Jass Help.
 

Nestharus

o-o
Reaction score
84
Ok, but admit the results are senseless, or at least weird.
I can't imagine a global array variable is about the same speed or faster (wtf !) than a global not array one.
Same for local array variable VS local not array variable.

The results are what they are, they show the truth of the JASS language that we work with.

I can only postulate as to why the hell a local array would be faster than a local variable ><.

I can also only postulate as to why the globals are pretty much same speed (-10% to 10% cancels).

Here are my theories-
Global variables are processed into global arrays in the background, making them the same speed as a regular array but taking up less memory as they are only one index.

A plain local variable is processed into a dynamic array stack just like the global. A local global variable is an actual generated array, but it's a little slower for JASS's strange scoping.

The local variable would be slower as it would be part of a stack. The local array would still be pretty slow because of the scoping.

That is about all I can think of to explain why the results are what they are.

Moved to Jass Help.

thank you : )

Again sorry for the misunderstanding ^_^.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top