Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/17/2013 in all areas

  1. Jon

    AutoIt v3.3.9.25 Beta

    File Name: AutoIt v3.3.9.25 Beta File Submitter: Jon File Submitted: 17 Dec 2013 File Category: Beta 3.3.9.25 (17th December, 2013) (Beta) AutoIt: UDFs: - Changed: _SQLite 3.8.1.0 -> 3.8.2.0. - Changed: _ArrayDisplay() - new function with new functionalities - Changed: GUIListView() - new _Delete* functions - Fixed #2550: _GUICombo_GetEditText() struct sizing Click here to download this file
    2 points
  2. BrewManNH

    Improved _ArrayAdd

    Here's a modification I made to the standard _ArrayAdd function from Array.au3. When used correctly, this function can drastically reduce the time needed to add multiple strings to an array without sacrificing any functionality. It has the same parameters as the standard _ArrayAdd function, but I've added a new one, which defaults to using the original if not used. The code below is a minor modification to the example script from the help file, I just modified it to time how long the operation takes, as well as adding 10, 000 entries to an already existing array. The first loop uses the current method of adding strings to an array, one at a time. The second loop creates a single string delimited by the pipe ("|") character containing 10,000 substrings, and then adding all 10,000 entries to the array in one _ArrayAdd call instead of 10,000 of them. If you run this from SciTE you will see just how much faster this method is than the original. The timing takes into account building the 10,000 substrings so the test is at least closer to being fair. The modified _ArrayAdd is in this demo script at the end of it, it is a drop in replacement for the original if you wanted to use it to replace it. #include <Array.au3> Global $avArray[10] $avArray[0] = "JPM" $avArray[1] = "Holger" $avArray[2] = "Jon" $avArray[3] = "Larry" $avArray[4] = "Jeremy" $avArray[5] = "Valik" $avArray[6] = "Cyberslug" $avArray[7] = "Nutster" $avArray[8] = "JdeB" $avArray[9] = "Tylo" Global $avArray2[10] $avArray2[0] = "JPM" $avArray2[1] = "Holger" $avArray2[2] = "Jon" $avArray2[3] = "Larry" $avArray2[4] = "Jeremy" $avArray2[5] = "Valik" $avArray2[6] = "Cyberslug" $avArray2[7] = "Nutster" $avArray2[8] = "JdeB" $avArray2[9] = "Tylo" _ArrayDisplay($avArray, "$avArray BEFORE _ArrayAdd()") $Timer = TimerInit() For $I = 1 To 10000 __ArrayAdd($avArray, "Test " & $I) Next ConsoleWrite("!Old method of _ArrayAdd = " & TimerDiff($Timer) / 1000 & @CRLF) _ArrayDisplay($avArray, "$avArray AFTER _ArrayAdd()") _ArrayDisplay($avArray2, "$avArray2 BEFORE _ArrayAdd()") $Timer = TimerInit() Global $sText = "" For $I = 1 To 10000 $sText &= "Test " & $I & "|" Next $sText = StringTrimRight($sText, 1) __ArrayAdd($avArray2, $sText, "|") ConsoleWrite("+New method of _ArrayAdd = " & TimerDiff($Timer) / 1000 & @CRLF) _ArrayDisplay($avArray2, "$avArray2 AFTER _ArrayAdd()") Func __ArrayAdd(ByRef $avArray, $vValue, $sDelim = "") If Not IsArray($avArray) Then Return SetError(1, 0, -1) If UBound($avArray, 0) <> 1 Then Return SetError(2, 0, -1) Local $iUBound = UBound($avArray), $aValue If $sDelim <> "" Then $aValue = StringSplit($vValue, $sDelim, 1) ; $STR_ENTIRESPLIT If Not @error Then ReDim $avArray[$iUBound + $aValue[0]] For $Loop = 0 To $aValue[0] - 1 $avArray[$iUBound + $Loop] = $aValue[$Loop + 1] Next Return $iUBound + $aValue[0] - 1 Else Return SetError(3, 0, -1) EndIf Else ReDim $avArray[$iUBound + 1] $avArray[$iUBound] = $vValue Return $iUBound EndIf EndFunc ;==>__ArrayAdd Enjoy!
    1 point
  3. Melba23

    GUI def as include ?

    Myicq, Firstly, you can #include files at any point within the script - all AutoIt does is to add the code at that point. Most includes are designed to be at the start of the script, but yours sounds like an obvious exception. However, I would not recommend doing this as you would have 2 scripts to maintain - change a variable name in one and the other will cease to function. If you use the #Region...#Endregion directives that are available with the full SciTE4AutoIt3 package then you can fold your 200 lines of code into a single one within SciTE - which gives you the same visual result but not the inter-file dependency. M23
    1 point
  4. lark

    Prime Numbers

    I'm surprised no one has mentioned prime sieves yet. Prime sieves work by filtering out non-primes, instead of checking whether each number is prime. The fastest sieve I've heard of is the sieve of atkin, which uses quadratics to determine prime numbers. Pseudo code on the wikipedia page is here: http://en.wikipedia.org/wiki/Sieve_of_Atkin Another popular prime sieve is the sieve of eratosthenes- its much simpler, but not quite as fast. Here is an implementation of the sieve of atkin in autoit: #include <Array.au3> Func getPrimes($limit) Local $isPrime[$limit] Local $i, $x, $y, $n For $i = 0 To $limit-1 $isPrime[$i] = False Next For $x = 1 To Sqrt($limit) For $y = 1 To Sqrt($limit) $n = 4*$x*$x + $y*$y If ($n <= $limit) And (Mod($n, 12) == 1 Or Mod($n, 12) == 5) Then $isPrime[$n] = Not $isPrime[$n] EndIf $n = 3*$x*$x + $y*$y If ($n <= $limit) And (Mod($n, 12) == 7) Then $isPrime[$n] = Not $isPrime[$n] EndIf $n = 3*$x*$x - $y*$y If ($x > $y) And ($n <= $limit) And (Mod($n, 12) == 11) Then $isPrime[$n] = Not $isPrime[$n] EndIf Next Next For $n = 5 To Sqrt($limit) If $isPrime[$n] Then $i = 1 $j = $i * $n * $n While $j < $limit $isPrime[$j] = False $i += 1 $j = $i * $n * $n WEnd EndIf Next Local $size = 2 For $i = 5 To UBound($isPrime)-1 If $isPrime[$i] Then $size += 1 Next Local $primes[$size] $primes[0] = 2 $primes[1] = 3 $i = 2 $j = 0 While $i < UBound($primes) If $isPrime[$j] Then $primes[$i] = $j $i += 1 EndIf $j += 1 WEnd Return $primes EndFunc Local $timer = TimerInit() Local $primes = getPrimes(100000) ConsoleWrite("Time taken: " & TimerDiff($timer) & @CRLF) _ArrayDisplay($primes) It took ~780 milliseconds to compute the first 100,000 primes on my computer, compared to ~45 seconds with the code above. -earthlark
    1 point
  5. Except the local variable that you wanted constant, is not constant.
    1 point
×
×
  • Create New...