| Posted: 09:58am 23 Nov 2025 |
Copy link to clipboard |
 Print this post |
|
To optimise performance do not use the same name for local variables in nested subroutines. Variables are created in a hash table. So by definition if you use i as an index in a subroutine called by a subroutine that also uses i. There will have been a hash table collision that the firmware resolves by looking for the next free slot. This is completely benign but does take extra time: not a lot but some.
Also, it is very slightly quicker if variables are typed at declaration rather than being typed with a suffix
Demo 1
fred ' Sub fred Local i%=22,ii%=23 bert Print i%,ii% End Sub ' Sub bert Local i%,j%,ii%,jj% Timer =0 For i%=1 To 100000 ii%=i% Next Print Timer Timer =0 For j%=1 To 100000 jj%=j% Next Print Timer End Sub Demo2
Option explicit Option default integer fred ' Sub fred Local i=22,ii=23 bert Print i,ii End Sub ' Sub bert Local i,j,ii,jj Timer =0 For i=1 To 100000 ii=i Next Print Timer Timer =0 For j=1 To 100000 jj=j Next Print Timer End Sub
|