| 06-26-2008, 04:52 PM | #1 |
I have always been wondering if a loop of is alot heavier to run than inlined codes. Example: 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 | ||||
JASS:scope A initializer init private function test takes nothing returns nothing local integer sw = StopWatchCreate() local integer i = 0 loop exitwhen i==100 call SquareRoot(i) set i = i+1 endloop call DebugPrint(R2S(StopWatchMark(sw)*1000)) call StopWatchDestroy(sw) endfunction private function init takes nothing returns nothing call TimerStart(CreateTimer(), 0.2, true, function test) endfunction endscope
JASS:scope A initializer init private function test takes nothing returns nothing local integer sw = StopWatchCreate() call SquareRoot( 0 ) call SquareRoot( 1 ) call SquareRoot( 2 ) call SquareRoot( 3 ) call SquareRoot( 4 ) call SquareRoot( 5 ) call SquareRoot( 6 ) call SquareRoot( 7 ) call SquareRoot( 8 ) call SquareRoot( 9 ) call SquareRoot( 10 ) call SquareRoot( 11 ) call SquareRoot( 12 ) call SquareRoot( 13 ) call SquareRoot( 14 ) call SquareRoot( 15 ) call SquareRoot( 16 ) call SquareRoot( 17 ) call SquareRoot( 18 ) call SquareRoot( 19 ) call SquareRoot( 20 ) call SquareRoot( 21 ) call SquareRoot( 22 ) call SquareRoot( 23 ) call SquareRoot( 24 ) call SquareRoot( 25 ) call SquareRoot( 26 ) call SquareRoot( 27 ) call SquareRoot( 28 ) call SquareRoot( 29 ) call SquareRoot( 30 ) call SquareRoot( 31 ) call SquareRoot( 32 ) call SquareRoot( 33 ) call SquareRoot( 34 ) call SquareRoot( 35 ) call SquareRoot( 36 ) call SquareRoot( 37 ) call SquareRoot( 38 ) call SquareRoot( 39 ) call SquareRoot( 40 ) call SquareRoot( 41 ) call SquareRoot( 42 ) call SquareRoot( 43 ) call SquareRoot( 44 ) call SquareRoot( 45 ) call SquareRoot( 46 ) call SquareRoot( 47 ) call SquareRoot( 48 ) call SquareRoot( 49 ) call SquareRoot( 50 ) call SquareRoot( 51 ) call SquareRoot( 52 ) call SquareRoot( 53 ) call SquareRoot( 54 ) call SquareRoot( 55 ) call SquareRoot( 56 ) call SquareRoot( 57 ) call SquareRoot( 58 ) call SquareRoot( 59 ) call SquareRoot( 60 ) call SquareRoot( 61 ) call SquareRoot( 62 ) call SquareRoot( 63 ) call SquareRoot( 64 ) call SquareRoot( 65 ) call SquareRoot( 66 ) call SquareRoot( 67 ) call SquareRoot( 68 ) call SquareRoot( 69 ) call SquareRoot( 70 ) call SquareRoot( 71 ) call SquareRoot( 72 ) call SquareRoot( 73 ) call SquareRoot( 74 ) call SquareRoot( 75 ) call SquareRoot( 76 ) call SquareRoot( 77 ) call SquareRoot( 78 ) call SquareRoot( 79 ) call SquareRoot( 80 ) call SquareRoot( 81 ) call SquareRoot( 82 ) call SquareRoot( 83 ) call SquareRoot( 84 ) call SquareRoot( 85 ) call SquareRoot( 86 ) call SquareRoot( 87 ) call SquareRoot( 88 ) call SquareRoot( 89 ) call SquareRoot( 90 ) call SquareRoot( 91 ) call SquareRoot( 92 ) call SquareRoot( 93 ) call SquareRoot( 94 ) call SquareRoot( 95 ) call SquareRoot( 96 ) call SquareRoot( 97 ) call SquareRoot( 98 ) call SquareRoot( 99 ) call DebugPrint(R2S(StopWatchMark(sw)*1000)) call StopWatchDestroy(sw) endfunction private function init takes nothing returns nothing call TimerStart(CreateTimer(), 0.2, true, function test) endfunction endscope
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...
Edited because: added 5x equivilants. Edited because: added averages. |
| 06-26-2008, 06:10 PM | #3 |
loops are not essential... // the set i = i+1 makes the biggest differense. |
| 06-27-2008, 04:01 PM | #4 |
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 |
Read the readme in the japi folder...
|
