Code: Select all
10 A=1
20 timer=0 : for Z=0 to 10000
30 if A=1 then gosub 110
40 next Z
50 print timer
60 timer=0 : for Z=0 to 10000
70 on A gosub 110
80 next Z
90 print timer
100 end
110 return
When run it outputs..
219
247
Which is a little odd as the whole idea of using ON is that it's supposed to be faster than using IF statements.
However when compiled it outputs..
40
39
So it is fractionally faster when compiled, but in this test there does not really seem to be much difference.
Next up a more complex test...
Code: Select all
10 A=1
20 timer=0 : for Z=0 to 10000
30 if A=1 then gosub 150
40 if A=2 then gosub 150
50 if A=3 then gosub 150
60 if A=4 then gosub 150
70 if A=5 then gosub 150
80 next Z
90 print timer
100 timer=0 : for Z=0 to 10000
110 on A gosub 150,150,150,150,150
120 next Z
130 print timer
140 end
150 return
outputs:
713
262
Compiled outputs:
85
39
So this now makes a lot more sense so if you only needed one IF condition, then using IF is probably fine as there is no real speed increase than using ON. However as most programs use multiple conditions, then clearly using ON results in double speed.