Let's try this one is without REGISTER Variables ...
Code:
FUNCTION PBMAIN () AS LONG LOCAL tc AS LONG #REGISTER NONE '===================================================================== tc = GetTickCount() LOCAL k AS LONG, i AS LONG LOCAL j AS LONG FOR i = 1 TO 30000 FOR j = 1 TO 30000 k+=7 NEXT j NEXT i ? STR$(GetTickCount - tc) END FUNCTION '=====================================================================
Now we use REGISTER Variables.
Should it be faster?
Code:
FUNCTION PBMAIN () AS LONG LOCAL tc AS LONG '===================================================================== tc = GetTickCount() REGISTER i AS LONG, j AS LONG LOCAL k AS LONG FOR i = 1 TO 30000 FOR j = 1 TO 30000 k+=7 NEXT j NEXT i ? STR$(GetTickCount - tc) END FUNCTION '===================================================================== END FUNCTION
It's even slower!
Maybe because of some Details of the FOR-LOOP.
If you do not want to pay the "47 Ticks", just use a DO ... LOOP and IF.
Now lets unleash the REAL POWER of PB REGISTER Variables!
By placing "k" into the REGISTER and removing "i".
Code:
FUNCTION PBMAIN () AS LONG LOCAL tc AS LONG '===================================================================== tc = GetTickCount() REGISTER k AS LONG, j AS LONG LOCAL i AS LONG FOR i = 1 TO 30000 FOR j = 1 TO 30000 k+=7 NEXT j NEXT i ? STR$(GetTickCount - tc) END FUNCTION '=====================================================================
RESULT: 516 Ticks USING PB REGISTER Variables!
Thats 4 times as fast as without using the REGISTER Variables!
Using the Loop-Variables as a REGISTER Variable is only good, if the Loop Variable is also often used inside the Loop.
Best is, if you put the most often accessed Variable into the REGISTER.
Leave a comment: