Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/23/2017 in all areas

  1. Change the while loop to this: While _IsPressed("45", $dll) Sleep(10) WEnd
    1 point
  2. Does this work? #include <Misc.au3> $dll = DllOpen("user32.dll") While 1 Sleep(10) ; If E key is pressed hold key S & F down until E is released If _IsPressed("45", $dll) Then Send("{s down}") ;Holds the s key down Send("{f down}") ;Holds the f key down While _IsPressed("57", $dll) Sleep(10) WEnd EndIf WEnd https://www.autoitscript.com/autoit3/docs/keywords/IfElseEndIf.htm https://www.autoitscript.com/autoit3/docs/libfunctions/_IsPressed.htm https://www.autoitscript.com/autoit3/docs/functions/Send.htm
    1 point
  3. Object from id: object = homepage_vyhl_frm_vozidlo Get object array of items: items = object.options For in loop: item in items Text of each object/select item: item.text Untested pseudo code: #include <IE.au3> Global $goMainIE = _IECreate("url here"); can use _IEAttach or _IECreate here If @error Then Exit 10011 Global $goID = _IEGetObjById($goMainIE, "homepage_vyhl_frm_vozidlo") If Not IsObj($goID) Then Exit 10012 Global $goItems = $goID.options If Not IsObj($goItems) Then Exit 10013 Global $gsItemList = "" For $oItem In $goItems $gsItemList &= $oItem.text & @CRLF Next MsgBox(64, "Items List", $gsItemList)
    1 point
  4. That vertical line is a feature of SciTE and is set by the edge.xxx keywords: (from the helpfile) edge.mode edge.column edge.colour Indicates long lines. The default edge.mode, 0, does not indicate long lines. An edge.mode of 1 uses a vertical line to indicate the specified column and an edge.mode of 2 changes the background colour of characters beyond that column. For proportional fonts, an edge.mode of 2 is more useful than 1. Jos
    1 point
  5. xan

    Fifteen Game Autoit

    Local $mx, $b[16], $bx[16], $by[16], $bn[16], $win, $enf, $rnd[16], $fr, $loop, $nMsg mix() While $nMsg <> -3 $nMsg = GUIGetMsg() If $nMsg = $mx Then mix() ; Botão mix If Not $loop Then For $i = 0 To 15 ; movimenta os botões selecionados Switch $nMsg Case $b[$i] GUICtrlSetBkColor($b[$i], 0x00cc33) Sleep(190) GUICtrlSetBkColor($b[$i], 0xffffff) if $i = 0 or $i = 4 Or $i = 8 Or $i = 12 Then pos($i, 2, 1, 1) if $i = 1 or $i = 5 Or $i = 9 Or $i = 13 Then pos($i, 1, 1, 1) if $i = 2 or $i = 6 Or $i = 10 Or $i = 14 Then pos($i, 0, 1, 1) if $i = 1 or $i = 5 Or $i = 9 Or $i = 13 Then pos($i, 0, -1, -1) if $i = 2 or $i = 6 Or $i = 10 Or $i = 14 Then pos($i, 1, -1, -1) if $i = 3 or $i = 7 Or $i = 11 Or $i = 15 Then pos($i, 2, -1, -1) if $i < 4 Then pos($i, 2, 4, 4) if $i > 3 And $i < 8 Then pos($i, 1, 4, 4) if $i > 7 And $i < 12 Then pos($i, 0, 1, 4) if $i > 3 And $i < 8 Then pos($i, 0, -4, -4) if $i > 7 And $i < 12 Then pos($i, 1, -4, -4) if $i > 11 Then pos($i, 2, -4, -4) Case -3 Exit EndSwitch GUICtrlSetPos($b[$i], $bx[$i], $by[$i]) ; Atualiza as posições dos botões If $bn[$i] <> $i + 1 Then $win = 1 ; Verifica se os botãoes estão ordenados Next EndIf If Not $win Then ; Animaçã da vitória If $loop < 2 Then For $i = 0 To 30 If $i < 16 Then GUICtrlSetBkColor($b[$i], Random(100, 10000, 1) * 5572 + $i * Random(100, 10000, 1)) If $i > 15 Then GUICtrlSetBkColor($b[$i-16], 0xffffff) Beep(Random(30, 100, 1) * $i, 250) Next EndIf $loop += 1 EndIf $win = 0 WEnd Func pos($n, $p, $sinal, $step) ; combinação para movimento dos botões For $i = $p To 0 Step - 1 if $bn[$n + $sinal * $i + $step] = 16 Then $aux = $b[$n + $sinal * $i] $b[$n + $sinal * $i]= $b[$n + $sinal * $i + $step] $b[$n + $sinal * $i + $step] = $aux $aux = $bn[$n + $sinal * $i] $bn[$n + $sinal * $i] = $bn[$n + $sinal * $i + $step] $bn[$n + $sinal * $i + $step] = $aux EndIf Next $nMsg = 0 EndFunc Func mix() ;Cria e embaralha os botões GUIDelete($fr) $fr = GUICreate("Autoit", 510, 560, 300, 50) GUISetBkColor(0xe8c70e) GUICtrlCreateLabel("JOGO DOS 15", 30, 15, 430, 70, 1) GUICtrlSetFont(-1, 54, 800, 0, "MS Sans Serif") $bt = GUICtrlCreateButton("", 38, 78, 434, 429) GUIctrlSetState(-1,128) $mx = GUICtrlCreateLabel("M i x", 422, 530, 50, 20, 1, 1) GUISetState() For $i = 0 To 3 ;gera as posições dos botões For $j = 0 To 3 $bx[$j + $i * 4] = $i * 3 + $j * 110 + 40 - 3 * $i $by[$j + $i * 4] = $i * 3 + $i * 105 + 80 Next Next $win = 0 $loop = 0 For $i = 0 to 15 Do $b[$i] = 0 $enf = 1 $rnd[$i] = Random(0, 15, 1) For $j = 0 To $i For $k = 0 To $i If $j <> $k And $rnd[$k] = $rnd[$j] Then $enf = 0 Next Next Until $enf $bn[$i] = $rnd[$i] + 1 If $rnd[$i] < 15 Then $b[$i] = GUICtrlCreateButton($rnd[$i] + 1, $bx[$i], $by[$i], 100, 100) GUICtrlSetBkColor($b[$i], 0xffffff) GUICtrlSetFont($b[$i], 50, 800, 0, "MS Sans Serif") EndIf Next EndFunc
    1 point
  6. Optimizing C# and VB code Index based sorting The examples in post 4 is an introduction to threading. The examples here shows how VB code can be optimized using multithreading. The examples are a continuation of the code in post 2 regarding index based sorting. Multithreaded sorting The idea is that if 4 threads are used to sort 100,000 rows, the first thread can sort the first 25,000 rows, the next thread can sort the next 25,000 rows, etc. It results in 4 indexes that finally can be combined into one big index. This is the code in Sort2DArrayOptEx.vb: Imports System Imports System.Threading Imports System.Collections Class SortArrayClass Dim aObjects, aCompare As Object(,) Dim iPartRows, iRestRows, iCmps As Integer Dim iThreads = 4, aIndex(iThreads)(), aRows(iThreads) As Integer Public Function Sort2DArray( aObjPar As Object(,), aCompPar As Object(,) ) As Integer() aObjects = aObjPar : aCompare = aCompPar Dim iRows As Integer = aObjects.GetUpperBound(1) + 1 iRestRows = iRows Mod iThreads : iPartRows = ( iRows - iRestRows ) / iThreads iCmps = aCompare.GetUpperBound(1) + 1 'Multithreaded index based sorting Dim th0 As New Thread( AddressOf Sort2DArraySub ) : th0.Start(0) Dim th1 As New Thread( AddressOf Sort2DArraySub ) : th1.Start(1) Dim th2 As New Thread( AddressOf Sort2DArraySub ) : th2.Start(2) Dim th3 As New Thread( AddressOf Sort2DArraySub ) : th3.Start(3) 'Main thread sleeps until sorting is done While aRows(0) = 0 Or aRows(1) = 0 Or aRows(2) = 0 Or aRows(3) = 0 Thread.Sleep(20) End While 'Combine four indexes into one Dim aIndexAll(iRows-1) As Integer Dim aIndexIdx(iThreads), iLeft, iRight, r, j As Integer For i As Integer = 0 To iRows - 1 iLeft = If( aIndexIdx(0) < aRows(0), 0, If( aIndexIdx(1) < aRows(1), 1, If( aIndexIdx(2) < aRows(2), 2, 3 ) ) ) iRight = iLeft While iRight < iThreads iRight += 1 Select iRight Case 1 iRight = If( aIndexIdx(1) < aRows(1), 1, If( aIndexIdx(2) < aRows(2), 2, If( aIndexIdx(3) < aRows(3), 3, iThreads ) ) ) Case 2 iRight = If( aIndexIdx(2) < aRows(2), 2, If( aIndexIdx(3) < aRows(3), 3, iThreads ) ) Case 3 iRight = If( aIndexIdx(3) < aRows(3), 3, iThreads ) End Select If iRight = iThreads Then Exit While r = 0 'Compare result (-1,0,1) j = 0 'Index in $aCompare array While r = 0 And j < iCmps r = If( aCompare(1,j), String.Compare( aObjects(aCompare(0,j),aIndex(iLeft)(aIndexIdx(iLeft))), aObjects(aCompare(0,j),aIndex(iRight)(aIndexIdx(iRight))) ), If( aObjects(aCompare(0,j),aIndex(iLeft)(aIndexIdx(iLeft))) < aObjects(aCompare(0,j),aIndex(iRight)(aIndexIdx(iRight))), -1, If( aObjects(aCompare(0,j),aIndex(iLeft)(aIndexIdx(iLeft))) > aObjects(aCompare(0,j),aIndex(iRight)(aIndexIdx(iRight))), 1, 0 ) ) ) * aCompare(2,j) j += 1 End While Select r Case 1 iLeft = iRight Case 0 If aIndex(iLeft)(aIndexIdx(iLeft)) > aIndex(iRight)(aIndexIdx(iRight)) Then iLeft = iRight End Select End While aIndexAll(i) = aIndex(iLeft)(aIndexIdx(iLeft)) aIndexIdx(iLeft) += 1 Next Return aIndexAll End Function 'Multithreaded index based sorting Private Sub Sort2DArraySub( oThread As Object ) Dim iThread As Integer = CInt( oThread ) Dim iFirstRow As Integer = If( iThread < iRestRows, iPartRows * iThread + iThread, iPartRows * iThread + iRestRows ) Dim iLastRow As Integer = iFirstRow + If( iThread < iRestRows, iPartRows, iPartRows - 1 ) Dim iRows As Integer = iLastRow - iFirstRow + 1 Dim MyList As New Generic.List( Of Integer ) MyList.Capacity = iRows MyList.Add(iFirstRow) 'Sorting by multiple columns Dim lo, hi, mi, r, j As Integer For i As Integer = iFirstRow + 1 To iLastRow lo = iFirstRow hi = i - 1 Do r = 0 'Compare result (-1,0,1) j = 0 'Index in $aCompare array mi = ( lo + hi ) / 2 While r = 0 And j < iCmps r = If( aCompare(1,j), String.Compare( aObjects(aCompare(0,j),i), aObjects(aCompare(0,j),MyList.Item(mi-iFirstRow)) ), If( aObjects(aCompare(0,j),i) < aObjects(aCompare(0,j),MyList.Item(mi-iFirstRow)), -1, If( aObjects(aCompare(0,j),i) > aObjects(aCompare(0,j),MyList.Item(mi-iFirstRow)), 1, 0 ) ) ) * aCompare(2,j) j += 1 End While Select r Case -1 hi = mi - 1 Case 1 lo = mi + 1 Case 0 Exit Do End Select Loop Until lo > hi MyList.Insert( If(lo=mi+1,mi+1,mi)-iFirstRow, i ) Next aIndex(iThread) = MyList.ToArray() aRows(iThread) = iRows End Sub End Class In Runtimes.au3 the execution times for sorting arrays with different number of rows are measuered for pure AutoIt code, for optimized VB code and for multithreaded VB code. This is the results on my PC: Code executed as 32 bit code Code executed as 64 bit code ============================ ============================ $iRows = 100, 6 columns $iRows = 100, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 4.3340 Pure AutoIt code: 3.7655 Optimized VB code: 1.2553 Optimized VB code: 1.4281 Multithreaded VB code: 19.0067 Multithreaded VB code: 33.5323 $iRows = 500, 6 columns $iRows = 500, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 27.5916 Pure AutoIt code: 25.5753 Optimized VB code: 2.6330 Optimized VB code: 2.8050 Multithreaded VB code: 31.2496 Multithreaded VB code: 36.4108 $iRows = 1000, 6 columns $iRows = 1000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 106.4464 Pure AutoIt code: 90.3135 Optimized VB code: 35.7356 Optimized VB code: 27.4234 Multithreaded VB code: 64.3406 Multithreaded VB code: 57.4474 $iRows = 2000, 6 columns $iRows = 2000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 142.1940 Pure AutoIt code: 134.2208 Optimized VB code: 11.6813 Optimized VB code: 10.9643 Multithreaded VB code: 30.2622 Multithreaded VB code: 33.4628 $iRows = 5000, 6 columns $iRows = 5000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 401.1128 Pure AutoIt code: 365.6661 Optimized VB code: 38.3885 Optimized VB code: 31.2551 Multithreaded VB code: 79.6997 Multithreaded VB code: 89.7060 $iRows = 10000, 6 columns $iRows = 10000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 826.2889 Pure AutoIt code: 691.7514 Optimized VB code: 70.5041 Optimized VB code: 65.1964 Multithreaded VB code: 89.2076 Multithreaded VB code: 60.4300 $iRows = 20000, 6 columns $iRows = 20000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 1816.3940 Pure AutoIt code: 1517.2513 Optimized VB code: 183.4977 Optimized VB code: 151.7480 Multithreaded VB code: 150.1049 Multithreaded VB code: 135.3445 $iRows = 50000, 6 columns $iRows = 50000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 5386.5884 Pure AutoIt code: 4239.2327 Optimized VB code: 602.9203 Optimized VB code: 471.3676 Multithreaded VB code: 373.1342 Multithreaded VB code: 371.5393 $iRows = 100000, 6 columns $iRows = 100000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 12798.0606 Pure AutoIt code: 9489.1929 Optimized VB code: 1590.7280 Optimized VB code: 1273.4829 Multithreaded VB code: 800.1118 Multithreaded VB code: 684.8815 $iRows = 250000, 6 columns $iRows = 250000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 44781.3723 Pure AutoIt code: 27407.9705 Optimized VB code: 7217.6899 Optimized VB code: 5222.3106 Multithreaded VB code: 2330.1729 Multithreaded VB code: 1914.2506 $iRows = 500000, 6 columns $iRows = 500000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 128479.2462 Pure AutoIt code: 69438.5295 Optimized VB code: 25016.8543 Optimized VB code: 16692.2426 Multithreaded VB code: 5949.0161 Multithreaded VB code: 4565.7862 $iRows = 750000, 6 columns $iRows = 750000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 250176.5552 Pure AutoIt code: 107785.2414 Optimized VB code: 54193.4737 Optimized VB code: 35217.0613 Multithreaded VB code: 10827.3308 Multithreaded VB code: 8186.0242 $iRows = 1000000, 6 columns $iRows = 1000000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 408457.7649 Pure AutoIt code: 162282.8254 Optimized VB code: 96291.4960 Optimized VB code: 62412.9602 Multithreaded VB code: 17399.9110 Multithreaded VB code: 12690.8546 $iRows = 2000000, 6 columns $iRows = 2000000, 6 columns Sort array by columns 0, 1, 2 Sort array by columns 0, 1, 2 ----------------------------------- ----------------------------------- Pure AutoIt code: 1445235.5246 Pure AutoIt code: 498648.9821 Optimized VB code: 409872.8400 Optimized VB code: 282116.6518 Multithreaded VB code: 63527.4207 Multithreaded VB code: 51087.1290 Code is added to "Examples\5) Optimizing C# and VB code\1) Index based sorting\" in zip-file in bottom of first post. Implementing a progress bar Another advantage of performing the sorting in 4 worker threads is that the main thread can be released by the VB code and thereby making the AutoIt code responsive while the sorting is going on. This makes it possible to implement a progress bar in the AutoIt code. The code in Sort2DArrayOptEx2.vb is changed a little bit: Imports System Imports System.Threading Imports System.Collections Class SortArrayClass Dim aObjects, aCompare As Object(,) Dim iRows, iPartRows, iRestRows, iCmps As Integer Dim iThreads = 4, aIndex(iThreads)(), aRows(iThreads) As Integer Public Sub Sort2DArray( aObjPar As Object(,), aCompPar As Object(,) ) aObjects = aObjPar : aCompare = aCompPar : iRows = aObjects.GetUpperBound(1) + 1 iRestRows = iRows Mod iThreads : iPartRows = ( iRows - iRestRows ) / iThreads iCmps = aCompare.GetUpperBound(1) + 1 'Multithreaded index based sorting Dim th0 As New Thread( AddressOf Sort2DArraySub ) : th0.Start(0) Dim th1 As New Thread( AddressOf Sort2DArraySub ) : th1.Start(1) Dim th2 As New Thread( AddressOf Sort2DArraySub ) : th2.Start(2) Dim th3 As New Thread( AddressOf Sort2DArraySub ) : th3.Start(3) End Sub 'Multithreaded index based sorting Private Sub Sort2DArraySub( oThread As Object ) Dim iThread As Integer = CInt( oThread ) Dim iFirstRow As Integer = If( iThread < iRestRows, iPartRows * iThread + iThread, iPartRows * iThread + iRestRows ) Dim iLastRow As Integer = iFirstRow + If( iThread < iRestRows, iPartRows, iPartRows - 1 ) Dim iSubRows As Integer = iLastRow - iFirstRow + 1 Dim MyList As New Generic.List( Of Integer ) MyList.Capacity = iSubRows MyList.Add(iFirstRow) 'Sorting by multiple columns Dim lo, hi, mi, r, j As Integer For i As Integer = iFirstRow + 1 To iLastRow lo = iFirstRow hi = i - 1 Do r = 0 'Compare result (-1,0,1) j = 0 'Index in $aCompare array mi = ( lo + hi ) / 2 While r = 0 And j < iCmps r = If( aCompare(1,j), String.Compare( aObjects(aCompare(0,j),i), aObjects(aCompare(0,j),MyList.Item(mi-iFirstRow)) ), If( aObjects(aCompare(0,j),i) < aObjects(aCompare(0,j),MyList.Item(mi-iFirstRow)), -1, If( aObjects(aCompare(0,j),i) > aObjects(aCompare(0,j),MyList.Item(mi-iFirstRow)), 1, 0 ) ) ) * aCompare(2,j) j += 1 End While Select r Case -1 hi = mi - 1 Case 1 lo = mi + 1 Case 0 Exit Do End Select Loop Until lo > hi MyList.Insert( If(lo=mi+1,mi+1,mi)-iFirstRow, i ) If ( i - iFirstRow ) Mod 1000 = 0 Then aRows(iThread) = i - iFirstRow Next aIndex(iThread) = MyList.ToArray() aRows(iThread) = iSubRows End Sub Public Function Sort2DArrayGetCount() As Integer Return aRows(0) + aRows(1) + aRows(2) + aRows(3) End Function Public Function Sort2DArrayGetIndex() As Integer() 'Combine four indexes into one Dim aIndexAll(iRows-1) As Integer Dim aIndexIdx(iThreads), iLeft, iRight, r, j As Integer For i As Integer = 0 To iRows - 1 iLeft = If( aIndexIdx(0) < aRows(0), 0, If( aIndexIdx(1) < aRows(1), 1, If( aIndexIdx(2) < aRows(2), 2, 3 ) ) ) iRight = iLeft While iRight < iThreads iRight += 1 Select iRight Case 1 iRight = If( aIndexIdx(1) < aRows(1), 1, If( aIndexIdx(2) < aRows(2), 2, If( aIndexIdx(3) < aRows(3), 3, iThreads ) ) ) Case 2 iRight = If( aIndexIdx(2) < aRows(2), 2, If( aIndexIdx(3) < aRows(3), 3, iThreads ) ) Case 3 iRight = If( aIndexIdx(3) < aRows(3), 3, iThreads ) End Select If iRight = iThreads Then Exit While r = 0 'Compare result (-1,0,1) j = 0 'Index in $aCompare array While r = 0 And j < iCmps r = If( aCompare(1,j), String.Compare( aObjects(aCompare(0,j),aIndex(iLeft)(aIndexIdx(iLeft))), aObjects(aCompare(0,j),aIndex(iRight)(aIndexIdx(iRight))) ), If( aObjects(aCompare(0,j),aIndex(iLeft)(aIndexIdx(iLeft))) < aObjects(aCompare(0,j),aIndex(iRight)(aIndexIdx(iRight))), -1, If( aObjects(aCompare(0,j),aIndex(iLeft)(aIndexIdx(iLeft))) > aObjects(aCompare(0,j),aIndex(iRight)(aIndexIdx(iRight))), 1, 0 ) ) ) * aCompare(2,j) j += 1 End While Select r Case 1 iLeft = iRight Case 0 If aIndex(iLeft)(aIndexIdx(iLeft)) > aIndex(iRight)(aIndexIdx(iRight)) Then iLeft = iRight End Select End While aIndexAll(i) = aIndex(iLeft)(aIndexIdx(iLeft)) aIndexIdx(iLeft) += 1 Next Return aIndexAll End Function End Class In Progressbar.au3 the execution times are measuered for the new code. This is the results on my PC when the code is run as 64 bit code: 250,000 rows Generate array Array generated 782.829209100278 Start sorting ... Sorting started 1052.33601879453 Sorting finished 3112.24138122098 Get index ... Index received 628.809605602899 500,000 rows Generate array Array generated 1692.53510123118 Start sorting ... Sorting started 1736.08362238057 Sorting finished 5300.57901794125 Get index ... Index received 987.373807333858 750,000 rows Generate array Array generated 2701.3300790124 Start sorting ... Sorting started 2846.97747093829 Sorting finished 8147.51853411496 Get index ... Index received 1427.32770753222 1,000,000 rows Generate array Array generated 3671.26491871585 Start sorting ... Sorting started 3360.98083976994 Sorting finished 11515.8238123206 Get index ... Index received 1913.89753875819 2,000,000 rows Generate array Array generated 7789.33304890347 Start sorting ... Sorting started 6773.98630303971 Sorting finished 48250.9211649065 Get index ... Index received 3852.50335220913 Note the lines titled "Sorting started". These are the lines that measure the time it takes to execute this code: Public Sub Sort2DArray( aObjPar As Object(,), aCompPar As Object(,) ) aObjects = aObjPar : aCompare = aCompPar : iRows = aObjects.GetUpperBound(1) + 1 iRestRows = iRows Mod iThreads : iPartRows = ( iRows - iRestRows ) / iThreads iCmps = aCompare.GetUpperBound(1) + 1 'Multithreaded index based sorting Dim th0 As New Thread( AddressOf Sort2DArraySub ) : th0.Start(0) Dim th1 As New Thread( AddressOf Sort2DArraySub ) : th1.Start(1) Dim th2 As New Thread( AddressOf Sort2DArraySub ) : th2.Start(2) Dim th3 As New Thread( AddressOf Sort2DArraySub ) : th3.Start(3) End Sub Most of the time is spent by passing the array ($aArray) as a parameter from the AutoIt code to the VB method (in aObjPar). Code is added to "Examples\5) Optimizing C# and VB code\1) Index based sorting\" in zip-file in bottom of first post. Global array variable Post 2 is a UDF version of four examples about generating a 2D array of random data, sorting the array by one or more columns through an index, converting the 2D array to a 1D array in CSV format, and finally saving the 1D array as a CSV file. The code is stored in "Examples\3) UDF version of examples\" in zip-file in bottom of first post. I've added a new example, ExampleOpt2.au3, to the Examples folder, where the execution times and the total execution time for these 4 procedures are measured for an array with 250,000 rows. This is the results: Code executed as 32 bit code Code executed as 64 bit code ============================ ============================ 250000 rows 250000 rows Generate array: 995.724559926393 Generate array: 797.652719123923 Sort array: 7236.27375117504 Sort array: 5291.30258795446 Convert array: 1426.65439887983 Convert array: 1224.09933028633 Save array: 450.983570086659 Save array: 383.220670832949 Total time: 10109.6362800679 Total time: 7696.27530819767 At the bottom of the example above we saw that quite a lot of time is being used to transfer arrays between the AutoIt code and the VB code. One way to avoid the time used to transfer arrays between AutoIt code and VB code is to store the array ($aArray/aObjects) as a global variable in the VB code. This is implemented in "Examples\5) Optimizing C# and VB code\2) Global array variable\Includes\ArrayFuncsOpt.vb". There is also used a multithreaded version of the sorting code. And the two procedures to convert and save the array as a CSV file is combined into one procedure to avoid transfering the array of strings back and forth. This is the time measurement for the new code: Code executed as 32 bit code Code executed as 64 bit code ============================ ============================ 250000 rows 250000 rows Generate array: 696.800872597593 Generate array: 516.643380589801 Sort array: 1542.99252546023 Sort array: 1465.04082474547 Save array: 446.520844017085 Save array: 418.329314718878 Total time: 2686.31424207491 Total time: 2400.01352005415 Code in "Examples\5) Optimizing C# and VB code\2) Global array variable\" in zip-file in bottom of first post. Delete global variables To delete global variables used in the VB code simply delete the object. The objects are solely handled in Includes\ArrayFuncsOpt.au3 UDF (there are no objects directly in the user code). The $oArrayClass object which is an instance of the ArrayClass in the VB code is created in ArrayFuncsOptInit() in this way: Func ArrayFuncsOptInit( $bDelObj = False ) Static $oNetCode = 0, $oArrayClass = 0 If $bDelObj Then $oArrayClass = 0 $oArrayClass = DotNet_CreateObject( $oNetCode, "ArrayClass" ) Return EndIf If IsObj( $oArrayClass ) Then Return $oArrayClass ; Compile and load VB code, create ArrayClass object $oNetCode = DotNet_LoadVBcode( FileRead( "..\Includes\ArrayFuncsOpt.vb" ), "System.dll" ) $oArrayClass = DotNet_CreateObject( $oNetCode, "ArrayClass" ) Return $oArrayClass EndFunc And the object is deleted in ArrayFuncsDelObject() by calling ArrayFuncsOptInit() with the $bDelObj parameter set to True: Func ArrayFuncsDelObject() ArrayFuncsOptInit( True ) EndFunc When the old object is deleted, a new object is created. ArrayFuncsDelObject() is called in bottom of ExampleOpt2.au3. Similar procedures are used in the example with the progress bar above to delete the old object and create a new.
    1 point
  7. Take a look to my SciTE properties. import au3.UserUdfs import au3.keywords.user.abbreviations font.base=font:Arial,size:10,$(font.override) font.monospace=font:Consolas,size:10 backup.files=0 proper.case=0 error.inline=1 highlight.current.word=1 highlight.current.word.by.style=1 highlight.current.word.autoselectword=0 highlight.current.word.wholeword=0 highlight.current.word.matchcase=0 highlight.current.word.minlength=3 use.tabs=1 indent.size=4 indent.size.*.au3=4 tabsize=4 style.*.32=style.*.32=$(font.base),back:#F0F4F9 caret.line.back=#FFFF00 caret.line.back.alpha=5 selection.fore=#CF6A4C selection.alpha=25 selection.back=#272822 style.error.0=fore:#FFFFFF,back:#D00064 style.error.1=fore:#FF0000,back:#FFFF00 style.error.2=fore:#FFFFFF,back:#FF0000 highlight.current.word.colour=#8080FF indicators.alpha=100 calltips.set.above=0 style.au3.38=fore:#FFFFFF,back:#171717 calltips.color.highlight=#FF0000 visible.policy.strict=1 visible.policy.lines=8 # Fold Margin fold.margin.colour=#222222 fold.margin.highlight.colour=#222222 # Output pane style.errorlist.32=back:#111111,fore:#ff0000 style.errorlist.4=fore:#40DFFF # Output pane style.au3.34=fore:#FF1A8C,back:#272822 style.au3.35=fore:#C0C0C0,italics,back:#272822 style.au3.0=fore:#11EAFB,back:#272822 style.au3.1=fore:#C0C0C0,italics,back:#272822 style.au3.2=fore:#C0C0C0,italics,back:#272822 style.au3.3=fore:#B58CFF,back:#272822 style.au3.4=fore:#FF75FF,back:#272822 style.au3.5=fore:#FF1A8C,back:#272822 style.au3.6=fore:#FFFF42,back:#272822 style.au3.7=fore:#00FF80,back:#272822 style.au3.8=fore:#FF8000,back:#272822 style.au3.9=fore:#FFFFFF,back:#272822 style.au3.10=fore:#FF8080,back:#272822 style.au3.11=fore:#F90000,back:#272822 style.au3.12=fore:#FFFF80,back:#272822 style.au3.13=fore:#00FFFF,back:#272822 style.au3.14=fore:#48A4FF,back:#272822 style.au3.15=fore:#2D96FF,back:#272822 style.au3.16=fore:#D26900,back:#272822 command.name.19.*= command.name.33.*= openpath.$(au3)=$(SciteDefaultHome)\..\include; font.quality=4 style.error.3=fore:#FFFFFF,back:#FF6400,bold,xfont:Consolas,size:12 caret.width=3 style.*.33=fore:#E4E4E4,back:#333333,$(font.base) style.au3.37=fore:#00AAFF,back:FFFFFF style.*.32=style.*.32=$(font.base),back:#F0F4F9 style.lua.0=fore:#F07070,bold style.lua.1=$(colour.code.comment.box),$(font.code.comment.box),back:#D0F0F0,eolfilled style.lua.2=$(colour.code.comment.line),$(font.code.comment.line) style.lua.3=$(colour.notused),bold,$(font.notused) style.lua.4=fore:#E000F4,bold,italics style.lua.5=fore:#0000FF,bold style.lua.6=fore:#F07070,bold style.lua.7=fore:#F07070,bold style.lua.8=fore:#F07070,bold style.lua.9=$(colour.preproc),bold style.lua.10=$(colour.operator),bold style.lua.11=fore:#808080,bold style.lua.12=back:#E0C0E0,bold,eolfilled style.lua.13=$(style.lua.5),bold,back:#F5FFF5 style.lua.14=$(style.lua.5),bold,back:#F5F5FF style.lua.15=$(style.lua.5),bold,back:#FFF5F5 style.lua.16=$(style.lua.5),bold,back:#FFF5FF style.lua.17=$(style.lua.5),bold,back:#FFFFF5 style.lua.18=$(style.lua.5),bold,back:#FFA0A0 style.lua.19=$(style.lua.5),bold,back:#FFF5F5 style.lua.20=fore:#7F7F00,bold braces.lua.style=10,bold file.patterns.props=*.properties;*.session;*.ini;*.inf;*.reg;*.url;*.cfg;*.cnf;*.aut;*.SciTEConfig style.props.0=fore:#000000,bold style.props.1=fore:#009000,bold,$(font.comment) style.props.2=$(colour.string),bold,back:#EFF0F0,eolfilled style.props.3=fore:#FF0000,bold style.props.4=$(colour.preproc) style.props.5=fore:#0060E0,bold style.props.33=fore:#000000,bold,back:#A0E0F0 style.*.32=style.*.32=$(font.base),back:#F0F4F9 style.props.34=fore:#0000FF,bold style.props.35=fore:#FF0000,bold style.json.0=fore:FFFFFF,bold style.json.1=fore:#007F7F,bold style.json.2=fore:#7F0000,bold style.json.3=fore:#FFFFFF,back:#FF0000,eolfilled style.json.4=fore:#880AE8,bold style.json.5=fore:#0B982E style.json.6=fore:#05BBAE,bold,italics style.json.7=$(style.json.6),bold style.json.8=fore:#18644A,bold style.json.9=fore:#0000FF,bold style.json.10=fore:#D137C1,bold style.json.11=fore:#0BCEA7,bold style.json.12=fore:#EC2806,bold style.json.13=fore:#FFFFFF,bold,back:#FF0000 style.au3.32=style.*.32=$(font.base),back:#272822 command.19.beta= command.33.beta= To Setup the ScITE properties go to C:\Users\Youruse\AppData\Local\AutoIt v3\SciTE and replace the SciTEUser.properties' info with the above one. Then your editor will look like: Saludos
    1 point
  8. The following implements two "similarity" functions. The first is the traditional Levenshtein method. The second is an algorithm adapted from http://siderite.blogspot.com/2007/01/super...-algorithm.html and re-coded for AutoIt. You can choose which implementation to use by passing a non-zero third parameter. This is my first code post so be kind! #include <Math.au3> Dim Const $maxOffset = 5 ; Change according to how far you want to search; a bigger value means a slower comparison ; Example usage MsgBox(0, "Levenshtein", _Similarity("The cat sat on the mat", "The dog sat on the cat")) MsgBox(0, "Similarity", _Similarity("The cat sat on the mat", "The dog sat on the cat", 1)) Exit ; Compute similarity between two strings Func _Similarity($s1, $s2, $alg = 0) Local $dis If ($alg = 0) Then $dis = _Levenshtein($s1, $s2) Else $dis = _Distance($s1, $s2) EndIf Local $maxLen = _Max(StringLen($s1), StringLen($s2)) If ($maxLen = 0) Then Return 100 Return (1 - $dis / $maxLen) * 100 EndFunc ; Compute Levenshtein Distance Func _Levenshtein($s, $t) Local $m, $n, $i, $j, $s_i, $t_j, $cost $n = StringLen($s) $m = StringLen($t) If $n * $m = 0 Then Return $m + $n Local $d[$n + 1][$m + 1] For $i = 0 To $n $d[$i][0] = $i Next For $j = 0 To $m $d[0][$j] = $j Next For $i = 1 To $n $s_i = StringMid($s, $i, 1) For $j = 1 To $m $t_j = StringMid($t, $j, 1) If $s_i = $t_j Then $cost = 0 Else $cost = 1 EndIf $d[$i][$j] = _Minimum3($d[$i - 1][$j] + 1, $d[$i][$j - 1] + 1, $d[$i - 1][$j - 1] + $cost) Next Next Return $d[$n][$m] EndFunc ; Get minimum of three values Func _Minimum3($a, $b, $c) Local $mi $mi = $a If $b < $mi Then $mi = $b If $c < $mi Then $mi = $c Return $mi EndFunc ; Efficient calculation of similarity Func _Distance($s1, $s2) Local $ls1 = StringLen($s1), $ls2 = StringLen($s2) If $ls1 * $ls2 = 0 Then Return $ls1 + $ls2 Local $c = 0, $offset1 = 0, $offset2 = 0, $dist = 0, $i While (($c + $offset1 < $ls1) And ($c + $offset2 < $ls2)) If (StringMid($s1, $c + $offset1 + 1, 1) <> StringMid($s2, $c + $offset2 + 1, 1)) Then $offset1 = 0 $offset2 = 0 For $i = 0 to $maxOffset - 1 If (($c + $i < $ls1) And (StringMid($s1, $c + $i + 1, 1) = StringMid($s2, $c + 1, 1))) Then If ($i > 0) Then $dist += 1 $offset1 = $i EndIf $dist -= 1 ExitLoop EndIf If (($c + $i < $ls2) And (StringMid($s1, $c + 1, 1) = StringMid($s2, $c + $i + 1, 1))) Then If ($i > 0) Then $dist += 1 $offset2 = $i EndIf $dist -= 1 ExitLoop EndIf Next $dist += 1 EndIf $c += 1 Wend Return $dist + ($ls1 - $offset1 + $ls2 - $offset2) / 2 - $c EndFunc WBD
    1 point
×
×
  • Create New...