HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

performance to the max?

06-26-2008, 04:52 PM#1
MaD[Lion]
I have always been wondering if a loop of is alot heavier to run than inlined codes. Example:
Collapse JASS:
local integer i = 0
loop
exitwhen i=1
 call BJDebugMsg("Slow?")
 set i = i+1
endloop

// is the above slower than:

 call BJDebugMsg("Fast?") //1

//-------------------------------
//If it is... then is it better to do:

local integer i = 0
loop
exitwhen i=100
 call BJDebugMsg("Fast?")
 set i = i+1
endloop

//than this:

 call BJDebugMsg("Slow?") //1
 call BJDebugMsg("Slow?") //2
 call BJDebugMsg("Slow?") //3
...
 call BJDebugMsg("Slow?") //100
06-26-2008, 05:12 PM#2
Alexander244
Expand JASS:

Output: 0.346 average

0.334
0.342
0.343
0.332
0.344
0.356
0.332
0.345
0.308
0.330
0.343
0.339
0.344
0.335
0.343
0.347
0.338
0.352
0.379
0.338
0.381
0.336
0.333
0.344
0.348
0.335
0.360
0.336
0.334
0.345
0.348
0.349
0.344
0.345
0.351
0.335
0.351
0.346
0.332
0.348
0.337
0.349
0.337
0.374
0.337
0.346
0.311
0.336
0.332
0.328
0.350
0.337
0.387
0.360
0.383
0.334
0.347
0.344
0.347
0.344
0.346
0.350
0.348
0.342
0.316
0.336
0.346
0.340
0.349
0.461
0.343
0.383
0.341
0.343


Expand JASS:

Output: 0.148 average

0.128
0.165
0.140
0.127
0.178
0.127
0.127
0.142
0.143
0.140
0.147
0.141
0.140
0.151
0.157
0.140
0.148
0.161
0.149
0.154
0.142
0.151
0.131
0.160
0.147
0.141
0.147
0.150
0.150
0.140
0.141
0.151
0.149
0.164
0.137
0.140
0.140
0.142
0.139
0.140
0.128
0.167
0.137
0.147
0.141
0.147
0.169
0.154
0.157
0.154
0.152
0.164
0.162
0.165
0.145
0.155
0.154
0.167
0.155
0.156
0.142
0.143
0.147
0.156
0.140
0.140
0.150
0.150
0.149
0.149
0.151


I didn't do BJDebugMsg as displaying text slows down with more messages.

When you actually do a normal amount within the loop, rather than a single native, the difference will presumably become trivial...

First with 5 Roots in the loop: 0.854 average

0.927
0.833
0.820
0.855
0.878
0.816
0.848
0.886
0.797
0.871
0.802
0.876
0.870
0.863
0.764
0.862
0.847
0.883
0.880
0.878
0.884
0.836
0.772
0.925
0.752
0.841
0.871
0.886
0.842
0.854
0.771
0.875
0.872
0.774
0.819
0.858
0.851
0.874
0.881
0.841
0.870
0.877
0.892
0.886
0.884
0.866
0.880
0.878
0.864
0.873
0.868


2nd Equivilent: 0.663 average

0.587
0.662
0.589
0.651
0.625
0.586
0.646
0.663
0.592
0.679
0.663
0.592
0.663
0.678
0.669
0.694
0.662
0.660
0.685
0.677
0.660
0.613
0.661
0.660
0.661
0.661
0.663
0.683
0.664
0.660
0.668
0.664
0.662
0.680
0.662
0.682
0.662
0.662
0.670
0.829
0.663
0.676
0.675
0.688
0.646
0.668
0.661
0.647
0.644
0.663
0.662
0.662
0.679
0.812


Edited because: added 5x equivilants.
Edited because: added averages.
06-26-2008, 06:10 PM#3
Toadcop
loops are not essential...
// the set i = i+1 makes the biggest differense.
06-27-2008, 04:01 PM#4
MaD[Lion]
hm so if there are alot fo codes in the loop then it is not much of a big difference hmm.. Thanks
So now tell me alex how to measure the execution time? Did u use a program ?
06-27-2008, 05:45 PM#5
Alexander244
Read the readme in the japi folder...
  • In both war3.lua and we.lua, uncomment (remove "--") from the front of the line that says injectdll(proc,"bin\japi.dll")
  • Import the common.j from the Japi folder to "scripts\common.j" in the test map.
  • The DebugPrint native prints to logs\nativepacklog.war3