I wondered about using bytes to store smaller values rather than integers, so I tried a speed test first with a byte:
sync on
global iMainLoopCount as integer
global dwStartTime as dword
global dwEndTime as dword
global byByte as byte
dwStartTime = hitimer()
repeat
inc byByte
if (byByte = 255)
byByte = 0
inc iMainLoopCount
endif
until (iMainLoopCount = 500000)
dwEndTime = hitimer()
do
set cursor 0,20
print "RUNTIME = " + str$(dwEndTime-dwStartTime)
nice wait 10
sync
loop
...and then with an integer:
sync on
global iMainLoopCount as integer
global dwStartTime as dword
global dwEndTime as dword
global iInt as integer
dwStartTime = hitimer()
repeat
inc iInt
if (iInt = 255)
iInt = 0
inc iMainLoopCount
endif
until (iMainLoopCount = 500000)
dwEndTime = hitimer()
do
set cursor 0,20
print "RUNTIME = " + str$(dwEndTime-dwStartTime)
nice wait 10
sync
loop
(Uses Matrix plugins)
On my system, the byte code took an average of 4700 ms. to complete. The integer code took 4000 ms.
I'm a bit surprised about this! Why does that happen? Wondered if any of you technical-minded people knew.
James.