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-
Variable definition for 100
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-
Arrays are 75% faster than hashtables
Global arrays are 35% faster than local variables
Global variables are anywhere from 10% slower to 10% faster than a global array
local arrays are 7.5% faster than local variables
Constant functions are in fact the same speed as regular functions
A global variable containing GetLocalPlayer() is 33% faster than a GetLocalPlayer() call
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.
* 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
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), 039;hpea039;, 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