ddeerr Posted October 18, 2006 Share Posted October 18, 2006 (edited) Hi, I would like a little precision about time execution if is it possible, cause i would like to optimize my code and (try) take good habits when i proramm. I have a simple example, what is the fastest between : expandcollapse popupFor $tempa = 1 To UBound($histoArray) - 1 Step 1 $siClef = StringSplit($histoArray[$tempa], "?") If Not @error Then GUICtrlCreateListViewItem("|" & $siClef[1] & "|" & $siClef[2] & "|" & $siClef[4] & "|" & $siClef[3] & "|" & $statusArray[$tempa], $Treeview_4) $a = 0 Else $a = 1 GUICtrlCreateListViewItem($histoArray[$tempa] & "| | | | |" & $statusArray[$tempa], $Treeview_4) EndIf Select Case $statusArray[$tempa] = "V" If $a = 0 Then GUICtrlCreateListViewItem("|" & $siClef[1] & "|" & $siClef[2] & "|" & $siClef[4] & "|" & $siClef[3] & "|" & $statusArray[$tempa], $Treeview_1) Else GUICtrlCreateListViewItem($histoArray[$tempa] & "| | | | |" & $statusArray[$tempa], $Treeview_1) Case $statusArray[$tempa] = "R" If $a = 0 Then GUICtrlCreateListViewItem("|" & $siClef[1] & "|" & $siClef[2] & "|" & $siClef[4] & "|" & $siClef[3] & "|" & $statusArray[$tempa], $Treeview_2) Else GUICtrlCreateListViewItem($histoArray[$tempa] & "| | | | |" & $statusArray[$tempa], $Treeview_2) Case $statusArray[$tempa] = "X" If $a = 0 Then GUICtrlCreateListViewItem("|" & $siClef[1] & "|" & $siClef[2] & "|" & $siClef[4] & "|" & $siClef[3] & "|" & $statusArray[$tempa], $Treeview_3) Else GUICtrlCreateListViewItem($histoArray[$tempa] & "| | | | |" & $statusArray[$tempa], $Treeview_3) EndSelect Next oÝ÷ ٩ݶjëh×6 For $tempa = 1 To UBound($histoArray) - 1 Step 1 $siClef = StringSplit($histoArray[$tempa], "?") If Not @error Then GUICtrlCreateListViewItem("|" & $siClef[1] & "|" & $siClef[2] & "|" & $siClef[4] & "|" & $siClef[3] & "|" & $statusArray[$tempa], $Treeview_4) If $statusArray[$tempa] = "V" Then GUICtrlCreateListViewItem("|" & $siClef[1] & "|" & $siClef[2] & "|" & $siClef[4] & "|" & $siClef[3] & "|" & $statusArray[$tempa], $Treeview_1) If $statusArray[$tempa] = "R" Then GUICtrlCreateListViewItem("|" & $siClef[1] & "|" & $siClef[2] & "|" & $siClef[4] & "|" & $siClef[3] & "|" & $statusArray[$tempa], $Treeview_2) If $statusArray[$tempa] = "X" Then GUICtrlCreateListViewItem("|" & $siClef[1] & "|" & $siClef[2] & "|" & $siClef[4] & "|" & $siClef[3] & "|" & $statusArray[$tempa], $Treeview_3) Else GUICtrlCreateListViewItem($histoArray[$tempa] & "| | | | |" & $statusArray[$tempa], $Treeview_4) If $statusArray[$tempa] = "V" Then GUICtrlCreateListViewItem($histoArray[$tempa] & "| | | | |" & $statusArray[$tempa], $Treeview_1) If $statusArray[$tempa] = "R" Then GUICtrlCreateListViewItem($histoArray[$tempa] & "| | | | |" & $statusArray[$tempa], $Treeview_2) If $statusArray[$tempa] = "X" Then GUICtrlCreateListViewItem($histoArray[$tempa] & "| | | | |" & $statusArray[$tempa], $Treeview_3) EndIf Next oÝ÷ Ù©Ýjëh×6 Switch Case $a = 1 Case $a = 2 Case $a = 3 EndSwitch tx for your replys Edited October 18, 2006 by ddeerr Link to comment Share on other sites More sharing options...
herewasplato Posted October 18, 2006 Share Posted October 18, 2006 Add a timer to the script of interest and see if it matters for your code.$begin = TimerInit() Sleep(1000) $delta = Int(TimerDiff($begin)) MsgBox(0, "Time Difference", $delta) [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
sulfurious Posted October 18, 2006 Share Posted October 18, 2006 There is a whole thread related to this topic that I found one time by searching. If I remember correctly, the order of speed was If EndIf was fastest, followed by Select EndSelect, followed by For Until, followed by While or Do loops. late, Sul Link to comment Share on other sites More sharing options...
tresa Posted October 18, 2006 Share Posted October 18, 2006 Hi, I would like a little precision about time execution if is it possible, cause i would like to optimize my code and (try) take good habits when i proramm. I have a simple example, what is the fastest between : several improvements - take in a variable the upper value of the loop. If the compiler is not good it will call the function for each loop -for code readability put outside the if the parts of code which are identical -put the listname in a varible as it's used in several lines of the code. gain in redability, not perf - use a switch and not if as for the first match the program will jump without testing further value. This is ok as your test is mutually exclusive - place the tests in the order of frquency from high to low, so the test will be ok in the first lines without going through all the code for "V" "R" "X" if X is the most frequently present put it first and so on $dimHisto=UBound($histoArray) - 1 For $tempa = 1 To $dimHisto Step 1 $siClef = StringSplit($histoArray[$tempa], "?") If Not @error Then $listViewName="|" & $siClef[1] & "|" & $siClef[2] & "|" & $siClef[4] & "|" & $siClef[3] & "|" & $statusArray[$tempa] Else $listViewName=$histoArray[$tempa] & "| | | | |" & $statusArray[$tempa] EndIf GUICtrlCreateListViewItem($listViewName, $Treeview_4) switch $statusArray[$tempa] Case "V" GUICtrlCreateListViewItem($listViewName, $Treeview_1) Case "R" GUICtrlCreateListViewItem($listViewName, $Treeview_2) Case "X" GUICtrlCreateListViewItem($listViewName, $Treeview_3) EndSwitch Next Link to comment Share on other sites More sharing options...
ddeerr Posted October 19, 2006 Author Share Posted October 19, 2006 several improvements - take in a variable the upper value of the loop. If the compiler is not good it will call the function for each loop -for code readability put outside the if the parts of code which are identical -put the listname in a varible as it's used in several lines of the code. gain in redability, not perf - use a switch and not if as for the first match the program will jump without testing further value. This is ok as your test is mutually exclusive - place the tests in the order of frquency from high to low, so the test will be ok in the first lines without going through all the code for "V" "R" "X" if X is the most frequently present put it first and so on $dimHisto=UBound($histoArray) - 1 For $tempa = 1 To $dimHisto Step 1 $siClef = StringSplit($histoArray[$tempa], "?") If Not @error Then $listViewName="|" & $siClef[1] & "|" & $siClef[2] & "|" & $siClef[4] & "|" & $siClef[3] & "|" & $statusArray[$tempa] Else $listViewName=$histoArray[$tempa] & "| | | | |" & $statusArray[$tempa] EndIf GUICtrlCreateListViewItem($listViewName, $Treeview_4) switch $statusArray[$tempa] Case "V" GUICtrlCreateListViewItem($listViewName, $Treeview_1) Case "R" GUICtrlCreateListViewItem($listViewName, $Treeview_2) Case "X" GUICtrlCreateListViewItem($listViewName, $Treeview_3) EndSwitch Next Hum, this is cooll i will do that try to clear and simplify the code. Finally If is greatest loop for simple thing and switch is beter than select i suppose (for redabilty). There is a whole thread related to this topic that I found one time by searching. If I remember correctly, the order of speed was If EndIf was fastest, followed by Select EndSelect, followed by For Until, followed by While or Do loops. late, SulCould you give this link if not i will search later. Tx all Link to comment Share on other sites More sharing options...
sulfurious Posted October 19, 2006 Share Posted October 19, 2006 Sorry, I have no idea what I used to search for, nor did I bookmark it. I think I was looking up some combination of 'loop' 'speed' 'performance' and maybe 'array'. As well, I may have been also using 'While loop speed' or 'Do loop speed'. later, Sul Link to comment Share on other sites More sharing options...
ddeerr Posted October 19, 2006 Author Share Posted October 19, 2006 Sorry, I have no idea what I used to search for, nor did I bookmark it. I think I was looking up some combination of 'loop' 'speed' 'performance' and maybe 'array'. As well, I may have been also using 'While loop speed' or 'Do loop speed'.later,SulThanks for that, is there a kind person which know and can indicate me where can i find information concerning memory usage of autoIt for example when you put a Local Variable in a function if when program quit function the memory is free.otherwise tx for all Link to comment Share on other sites More sharing options...
ame1011 Posted October 19, 2006 Share Posted October 19, 2006 (edited) Also, use += or *= or -= etc. whenever you can over their longer counterparts. Below is a script that tests the speed of a function that uses the += operator and one that doesnt. expandcollapse popup#include <Array.au3> $aa = _ArrayCreate(-1) $bb = _ArrayCreate(-1) $sum = 0 $avg = 0 func a() $timer = TimerInit() $y=0 for $x = 0 to 10000 $y += 1 Next $diff = TimerDiff($timer) return $diff EndFunc func b() $timer = TimerInit() $y=0 for $x = 0 to 10000 $y = $y + 1 Next $diff = TimerDiff($timer) return $diff EndFunc for $i = 0 to 50 $d = a() _ArrayAdd($aa, $d) Next for $v = 1 to Ubound($aa) -1 $sum += $aa[$v] Next $avg = $sum / (Ubound($aa) -1) ConsoleWrite("a_avg="&$avg&@cr) for $i = 0 to 50 $d = b() _ArrayAdd($bb, $d) Next for $v = 1 to Ubound($bb) -1 $sum += $bb[$v] Next $avg = $sum / (Ubound($bb) -1) ConsoleWrite("b_avg="&$avg&@cr) After 50 iterations of the method, which in turn interates 10000 times, the += operator appears to be more than twice as fast as the 'old' method. I know it doesnt apply in this case, but its good to keep in the back of your mind for future scripts that require a fast runtime. Edited October 19, 2006 by ame1011 [font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font] Link to comment Share on other sites More sharing options...
ddeerr Posted October 19, 2006 Author Share Posted October 19, 2006 After 50 iterations of the method, which in turn interates 10000 times, the += operator appears to be more than twice as fast as the 'old' method.I know it doesnt apply in this case, but its good to keep in the back of your mind for future scripts that require a fast runtime.Of course i'll remember that thanks a lot Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now