I made this simple test - calling a function which simply has nested do loops.
In one version, Local is used to declare loop variables i,j. In the second version, REGISTER is used to declare the loop variables.
When timed, both give approximately the same answer. Based on what I read in Help, I was expecting a very noticeable difference. Were my expectations too high? Or have I used REGISTER incorrectly?
In one version, Local is used to declare loop variables i,j. In the second version, REGISTER is used to declare the loop variables.
When timed, both give approximately the same answer. Based on what I read in Help, I was expecting a very noticeable difference. Were my expectations too high? Or have I used REGISTER incorrectly?
Code:
#Compile Exe #Dim All #Include "win32api.inc" Function PBMain() As Long Local hDlg As Dword Dialog New Pixels, 0, "Button Test",300,300,200,200, %WS_OverlappedWindow To hDlg Control Add Button, hDlg, 100,"Push", 50,10,100,20 Dialog Show Modal hDlg Call DlgProc End Function CallBack Function DlgProc() As Long If Cb.Msg = %WM_Command And Cb.Ctl = 100 And Cb.CtlMsg = %BN_Clicked Then Dim iStart As Long, iEnd As Long, Result As String iStart = GetTickCount MySub_Slow iEnd = GetTickCount MsgBox "Slow: " + Format$((iEnd - iStart)/1000,3) & " seconds" iStart = GetTickCount MySub_Fast iEnd = GetTickCount MsgBox "Fast: " + Format$((iEnd - iStart)/1000,3) & " seconds" End If End Function Sub MySub_Slow Local i As Long, j As Long Local x As Single For i = 1 To 1000000 For j = 1 To 2000 x = i Next j Next i End Sub Sub MySub_Fast Register i As Long, j As Long Local x As Single For i = 1 To 1000000 For j = 1 To 2000 x = i Next j Next i End Sub
Comment