Jump to content
Sign in to follow this  
qsek

Advanced Questions about Databases, StringSplit, 2D Arrays and performance

Recommended Posts

qsek

Hi,

Lets assume i have a String like in this Format:

"0 EKClan Daniel091189 1 60 1 1 1 0 1 0 66471681 0 0 0.0 0 0 0 7 78.54.38.73 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 CH_Engineer 4376.334801 0 0 [13]

1 EKClan xX-rising_$hadow 2 28 1 1 1 0 1 0 103051468 0 0 0.0 0 0 0 3 213.39.230.245 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 US_Medic 4871.363935 0 0 [13]

3 oldmargie 2 46 1 1 1 0 1 0 48876969 0 0 0.0 0 0 0 3 86.31.253.105 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 US_AT 5021.983612 0 0 [13]

2 OLEG@TORru 1 89 1 1 1 0 1 0 139942352 0 0 0.0 0 0 0 7 91.144.149.83 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 CH_Specops 5280.310828 0 0 [13]

[4]"

the numbers in [] are originally special Characters which evals chr(number), i only changed these for better understanding. Every space between the numbers evals a TAB char: chr(9)

Every Row represents a Player with have the first number as ID and all the other values are informations about that player.

I cant change the format of that String i get. I have to work with this. And i need almost all values for later processing.

So until now i used StringSplit($string,chr(13)) to get the rows and for every row: StringSplit($row,chr(9)) to get the values.

Then i put every row into a 2D Array. But not one after another, i use the first row value (ID) as index for the row to insert. I have to do this cause i get these indexes unsorted in this String.

The ID is always a number between 0 and 63.

for example $Array[3][1] would be "oldmargie" in this example, cause the first value of the oldmargie row is "3"

with this array i work in my whole script.

eg.

if Array[$i][4] = "1" and not Array[$i][4] then .....
elseif Array[$i][1] and not Array[$i][1] then .....
Endif

So the clue comes now:

This whole processing from getting the String, populating the 2D Array, processing all conditions is looped every second!

So i have an input stream of this String which i have to compare constantly to the previous String for differences in the values.

But this solution of mine is very CPU intensive.

Lets assume the worsest case: I have 64 Players, ergo 64 rows to StringSplit, put into 2D Array and so on....

This will eat almost 50% of a single core 2Ghz CPU and takes more than 1000ms to execute constantly every second.

Now simplified: My question is, how can i process this String the fastest and less CPU intensive way you can do with autoit.

I guess there could be applied solutions with using DLL CALL's or even making an own dll for this purpose.

Or using SQLite.

I've looked into these possibilities, but they are a bit too complex to get and idea, if this is possible and the best way to use.

So i ask you programming gurus how to best approach to this problem.

Edited by qsek

Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

Share this post


Link to post
Share on other sites
weaponx

You didn't provide enough information.

Why are they numbered 0,1,3,2?

Why is there an extra [4] at the end?

Does each row always have the same number of elements?

Which fields do you need to track for changes?

What do you need to do if a field changes?

What does this even mean? "the numbers in [] are originally special Characters which evals chr(number)"

Share this post


Link to post
Share on other sites
qsek

Why are they numbered 0,1,3,2?

This String is a TCPRecv from a game server, i cant change what the game server gives me in return from a TCPSend command.

The numbers are the player Slots and unsorted. I cant change it.

What does this even mean? "the numbers in [] are originally special Characters which evals chr(number)"

Why is there an extra [4] at the end?

the [4] equals the special ACII character chr(4) also known as EOT (End of Transmission) which is used by the server to finish his output.

I just replaced it for a better visibility, cause you cant make Control Characters visible in the forum ^^

Does each row always have the same number of elements?

Yes, there are 46 values per row, mixed Int,float and string.

Which fields do you need to track for changes?

basically almost all values.

What do you need to do if a field changes?

Very different things, for example if a kill value changed the player made a frag --> give out a message.

If the dead value change to 1 use another picture for the player.

But that i want to make with native Autoit functions.

All i want to optimize is, how to process this string into a temporary fast accessable database, which is easy to use with if statements.

Edited by qsek

Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

Share this post


Link to post
Share on other sites
weaponx

Is each line seperated by @CRLF or by this control character? You can check by opening the text in SciTe and clicking View > End of Line, or by outputting the return from TcpRecv to the console.

Share this post


Link to post
Share on other sites
qsek

each line sparated by chr (13) = @CR

Like i said its easy to do StringSplit($string,chr(13)) and StringSplit($row,chr(9)) and in a Loop _ArrayReplace2DRow($Array, $row, $row[0]))

But on 64x46 dimension and executed every second, this is a huge impact to the CPU.

For example would it be possible to pass this string to a dll, make all splitting, arranging and comparing there, and have an UDF like _PlayerInfo($Slot,$value) or _PlayerEvent($Slot,$value)

which does the apropiate DLL Call? And even more: would it be faster and less CPU intensive?

Edited by qsek

Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

Share this post


Link to post
Share on other sites
qsek

here is a stripped down example out of my script, there you see the actual CPU usage, if its running and the miliseconds it takes to execute:

#include <GUIConstants.au3>
#include <Array.au3>
#include <File.au3>
#Include <Date.au3>
#include <String.au3>
;~ #include <Array2D.au3>


;~ ProcessSetPriority(@AutoItPID,4) ; for better results with timers

Opt("GUIOnEventMode",1)


; ### Populating an Array with 10 Input Strings
dim $recvArr[10]
dim $DataType[46] = [0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1,0,0,2,0,3,0,2,0,0,0]

for $z = 0 to 9
    $String = ""
    for $r = 0 to 63
        for $t = 0 to 45
            if $t = 0 then 
                $String &= $r&@TAB
                ContinueLoop
            Endif
            switch $DataType[$t]
                case 0 ; Int
                    $String &= Random(0,1,1)&@TAB
                case 1 ; float
                    $String &= Random(0,1,1)&@TAB
                case 2 ; String
                    for $p = 0 to Random(5,10,1)
                        $String &= chr(Random(65,122,1))
                    next
                    $String &= @TAB
                case 3 ; 3D coordiantes
                    $String &= Random(-100,100)&","&Random(-100,100)&","&Random(-100,100)&@TAB
            EndSwitch

            if $t = 45 then
                $String = StringTrimRight($String,1)
                if $r <> 63 then $String &= @CR
            Endif
        next
    next
    $recvArr[$z] = $String
next
; ###


$e = 0

$tick = @SEC


Dim $Plinfo[64][30]
Dim $Playerinfo[64][46] ; this is the Array i want to have fast access to
$LastPlayerinfo = $Playerinfo ; this is the data of the previous second, that i want to compare

$timer2= TimerInit() ; timer for whole Loop

$timer3= TimerInit() ; Timer for using inside of Loop

; #### Main Loop ####
While 1
    Sleep(20)
    If $tick <> @SEC then 
;~      Times(-2)
        
        GetPlayerInfo()
        
            $timer2= TimerInit()
            global $timersub[1][3]
            $timer3= TimerInit()
        UpdatePlayerPos()
        UpdatePlayerPos() ; represents all the stuff code

        showtimerdiff(@ScriptLineNumber,$timer2,"UpdatePlayerPos(Total)")
            showtimerdiffsubfinish("Sub UpdatePlayerPos")
            
    Endif
    $tick = @SEC
wend
; ####


Func GetPlayerInfo()

    $timer2= TimerInit()
    
    $Playerdata = StringSplit($recvArr[$e], chr(13))
    
;~  _ArrayDisplay($Playerdata)
    Dim $Playerinfo[64][46] ; clear current Player info

    For $i = 1 To $Playerdata[0] ; Zeile

        if not $Playerdata[$i] then ContinueLoop

        $tmpline = _StringSplit2($Playerdata[$i], Chr(9))
;~      _ArrayDisplay($tmpline)
        If UBound($tmpline) = 46 Then ; if row valid

            __ArrayReplace2DRow ($Playerinfo, $tmpline, $tmpline[0]+0) ; refresh Row/PlayerSlot

;~          $Playerinfo[$tmpline[0]] = $tmpline
        Else
            ConsoleWrite("Error: Corrupt Player info data at Zeile: "&$i & ""&UBound($tmpline)&""& @CRLF)
            ContinueLoop
        EndIf
    Next
    
;~  _ArrayDisplay($Playerinfo)

    $e += 1 ; move to the next Stringdata
    if $e = 3 then $e = 0
        
    showtimerdiff(@ScriptLineNumber,$timer2,"GetPlayerinfo")
EndFunc

Func UpdatePlayerPos()

    for $i = 0 to 63


        $timer3= TimerInit()

        ;###################################################################
        ;############ Loop, New Player and Connecting Issues ###############
        if Not $LastPlayerinfo[$i][1] then
            if Not $Playerinfo[$i][1] then
                ContinueLoop; no player
            elseif $Playerinfo[$i][4] = "0" then
;~              ConsoleWrite("Player connecting: " & $Playerinfo[$i][1] & "(Slot " & $i & ")"&$i)
                ; ~ stuff~
                ContinueLoop
            endif   
        elseif not $Playerinfo[$i][4] then
            ConsoleWrite("Still connecting..." & @CRLF)
            ContinueLoop
        elseif $LastPlayerinfo[$i][1] And not $Playerinfo[$i][1] then
            ConsoleWrite("Disconnected" & @CRLF)
            ; ~ stuff~
            $LastPlayerinfo = $Playerinfo
            ContinueLoop
        Endif

        showtimerdiffsub(@ScriptLineNumber,$timer3,"Loop, New Player..")

        dim $Plviol[64][50]
        $Plviol[$i][5] = ""
        $Plviol[$i][10] = ""
        $Plviol[$i][15] = ""
        $Plviol[$i][20] = ""
        $Plviol[$i][25] = ""
        $Plviol[$i][30] = ""
        $Plviol[$i][31] = ""
        
        global $ttsent  = 0
        global $consend = 0
        dim $AlivePlcount[5]
        $AlivePlcount[3] = $AlivePlcount[1]
        $AlivePlcount[4] = $AlivePlcount[2]
        $AlivePlcount[1] = 0
        $AlivePlcount[2] = 0
        local $fragskillsRound = 0
        local $warned = 0
        global $Plevent[64][41] ; Reset the Events
        global $Plfragevents[64][12] ; reset the Frag Infos
                
        If $Playerinfo[$i][4] = 1 and $LastPlayerinfo[$i][4] == "0" and $Playerinfo[$i][8] = "0" Then ; Player finished loading but still dead
            if $Plinfo[$i][1] then
                if $ttsent then ConsoleWrite($Playerinfo[$i][42] & @CRLF)
            else
;~              ConsoleWrite("Player "&$Playerinfo[$i][1]&" connected."&$i)
            Endif

;~          ConsoleWrite("Spieler "&$Playerinfo[$i][1]&" hat fertig geladen, ist noch tot")

            $LastPlayerinfo[$i][4] = $Playerinfo[$i][4]

        Endif

        if $LastPlayerinfo[$i][1] = "" and $Playerinfo[$i][1] then  ; New Player loaded
;~          ConsoleWrite("Slot init:"&$i & @CRLF)
            $Plfragevents[$i][5] = 1
            $Plinfo[$i][13] = TimerInit() ; Start zone Timer
            Switch $Playerinfo[$i][33]
                case 8
                    $Plinfo[$i][11] = 0
                case 0,2,4,6
                    $Plinfo[$i][11] = 1
                case 1,3
                    $Plinfo[$i][11] = 2
                case 5,7,11
                    $Plinfo[$i][11] = 3
            endswitch
;~          SetSprite($i)
        Endif
        showtimerdiffsub(@ScriptLineNumber,$timer3,"finished loading")
        

        ;#############################################
        ;############ Create Playerevents ############
        
        Dim $Eventrows[30] = ["0","1","2","4","8","9","12","14","15","16","19","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40"]

        for $z in $Eventrows
            $Plevent[$i][$z] = ""
            if $LastPlayerinfo[$i][$z] == $Playerinfo[$i][$z] then ContinueLoop
            
            if StringIsInt($LastPlayerinfo[$i][$z]) or StringIsInt($Playerinfo[$i][$z]) then
                if $LastPlayerinfo[$i][$z]+0 > $Playerinfo[$i][$z]+0 Then
                    $Plevent[$i][$z] = "-1" ; Changed Down 1 --> 0
                elseif $LastPlayerinfo[$i][$z]+0 < $Playerinfo[$i][$z]+0 Then
                    $Plevent[$i][$z] = "1" ;  Changed Up   0 --> 1
                Endif
            else
                if $LastPlayerinfo[$i][$z] <> $Playerinfo[$i][$z] Then $Plevent[$i][$z] = "2" ; String Change
            Endif

            if not $LastPlayerinfo[$i][$z] and $Playerinfo[$i][$z] then ; New Player has no events
                $Plevent[$i][$z] = ""
            Endif
            
        next
        showtimerdiffsub(@ScriptLineNumber,$timer3,"eventrows")

        Dim $tmp2 = 0
        for $u = 0 to Ubound($Plevent,2)-1
            if $Plevent[$i][$u] then
                $tmp2 = 1
                ExitLoop ; check if there was an event
            endif
        next
        
        showtimerdiffsub(@ScriptLineNumber,$timer3,"check if event")
        if not ($Playerinfo[$i][8] = 0 or $Playerinfo[$i][9] = 1) then ; Player alive
            $AlivePlcount[$Playerinfo[$i][2]] += 1
        Endif
        
        if not $tmp2 and $LastPlayerinfo[$i][1] <> "" then
            ContinueLoop ; Nothing Changed
        Endif

        ; ########### Corrections ###########
        if ($Plevent[$i][8] = 1 or $Plevent[$i][9] = -1) and $Plevent[$i][40]= "" and $LastPlayerinfo[$i][9] <> 1 then
            if $Plevent[$i][8] = 1 then $Playerinfo[$i][8] = "0" ; Reset
            if $Plevent[$i][9] = -1 then $Playerinfo[$i][9] = "1" ; Reset
            ConsoleWrite($Playerinfo[$i][1] & " has spawned, but no poschange  --> next time")
            for $t = 0 to 44
                if $t = 40 then Continueloop
                $Playerinfo[$i][$t] = $LastPlayerinfo[$i][$t]
            next
        Endif
        
; ~ stuff~

; ~ stuff~

; ~ stuff~



        showtimerdiffsub(@ScriptLineNumber,$timer3,"Corrections and stuff")
        
        
        
        
        ; ##########################################################
        ; ###################### Get Distance ######################
        $Flagdist = ""
        
        if not ($Playerinfo[$i][8] = 0 or $Playerinfo[$i][9] = 1) then ; Player alive
            $zo = ""
            $lastzo = $Plviol[$i][0]
            if $Playerinfo[$i][40] then ; Flags

                for $w = 0 to 5 ; Get the distance to certain players
                    if $Playerinfo[$w][40] = "" then ContinueLoop ; no player

                    $tmpPlayerPos = StringSplit($Playerinfo[$i][40], ",")
                    $tmpLastPlayerPos = StringSplit($Playerinfo[$w][40], ",")
                    $tmpdist = 50
                    $tmpdist = GetD($tmpPlayerPos[1],$tmpPlayerPos[2],$tmpPlayerPos[3],$tmpLastPlayerPos[1],$tmpLastPlayerPos[2],$tmpLastPlayerPos[3])
                    if not $Flagdist then
                        $Flagdist = $tmpdist
                    elseif $tmpdist < $Flagdist Then ; find the smallest Distance
                        $Flagdist = $tmpdist
                    endif
                    ContinueLoop
                next
                
                
                for $w = 0 to 63 ; Get the distance to every other player
                    if $Playerinfo[$w][40] = "" then ContinueLoop ; no player

                    $tmpPlayerPos = StringSplit($Playerinfo[$i][40], ",")
                    $tmpLastPlayerPos = StringSplit($Playerinfo[$w][40], ",")
                    $tmpdist = 50
                    $tmpdist = GetD($tmpPlayerPos[1],$tmpPlayerPos[2],$tmpPlayerPos[3],$tmpLastPlayerPos[1],$tmpLastPlayerPos[2],$tmpLastPlayerPos[3])
                    if not $Flagdist then
                        $Flagdist = $tmpdist
                    elseif $tmpdist < $Flagdist Then ; find the smallest Distance
                        $Flagdist = $tmpdist
                    endif
                    ContinueLoop
                next
                
                
                $tdif = TimerDiff($Plinfo[$i][13])
                
                ; ############ Camping #################
                if  ($Plevent[$i][2]=1) then
                
                ; ~ lots of stuff~
                
                ; ~ lots of stuff~
                
                ; ~ lots of stuff~
                
                elseif 1 then
                    if $Flagdist < 20 then ; closer than 10 meters
                        $Plviol[$i][0] = -1
                    else
                        $Plviol[$i][0] = ""
                    endif
                endif
            Endif


            $Plinfo[$i][15] = $Flagdist

            if $lastzo <> $Plviol[$i][0] or ($zo > 1 and $Plinfo[$i][13] = "") then 
                $Plinfo[$i][13] = TimerInit()
            endif
            
        endif
        showtimerdiffsub(@ScriptLineNumber,$timer3,"get distance")
        
    ;###################################################
    ;############ Player Game Events ###################

                        
                ; ~ lots of stuff~
                
                ; ~ lots of stuff~
                
                ; ~ lots of stuff~
                


        showtimerdiffsub(@ScriptLineNumber,$timer3,"Gameevents")
        
    next
    $LastPlayerinfo = $Playerinfo
EndFunc







Func _StringSplit2($sStr, $sSepF, $iFlag = 0)
    Local $sTmp = $sStr, $arFileF[1] = [$sStr], $iPos, $iPos1, $sLenSep = StringLen($sSepF), $iCaseSens = 1
    If $sSepF = "" Then ;handle empty splitter separator
        $iPos = 2
        $sTmp = StringLeft($sStr, 1)
        ; if Sep has more than 1 character, we must first check for ;split the Separator into individual characters
    ElseIf Not $iFlag And $sLenSep > 1 Then ;maybe we should use RegExp
        ; check the first character as separator, to find likely $iPos candidate
        Local $aSep = StringSplit($sSepF, "", 1) ;split the Separator into individual characters
        $iPos = StringInStr($sTmp, $aSep[1], $iCaseSens)
        $sTmp = StringLeft($sTmp, $iPos - 1) ;keep as short as possible
        For $c = 2 To UBound($aSep) - 1; loop through the rest of the separators in case any are sooner
            $iPos1 = StringInStr($sTmp, $aSep[$c ], $iCaseSens)
            If $iPos1 And $iPos1 < $iPos Then ;must be found, and < $iPos
                $iPos = $iPos1
                $sTmp = StringLeft($sTmp, $iPos - 1) ;keep as short as possible
            EndIf
        Next
    Else ;if $iFlag=1 or only 1 character, above not needed
        If $sLenSep > 1 Then $iCaseSens = 0 ;stringsplit is NOT case-sensitive if more than 1 char in separator, used as 1
        $iPos = StringInStr($sStr, $sSepF, $iCaseSens)
        $sTmp = StringLeft($sStr, $iPos - 1)
    EndIf
    If Not $iPos Then Return SetError(@error, 0, $arFileF)
    If Not $iFlag And $sLenSep Then $sLenSep = 1 ;change length for single char separators of "0" $iFlag
    $sStr = StringMid($sStr, $iPos + $sLenSep)
    $arFileF = StringSplit($sStr, $sSepF, $iFlag)
    $arFileF[0] = $sTmp
    Return SetError(0, 0, $arFileF);$arFileF
EndFunc   ;==>_StringSplit2


Func __ArrayReplace2DRow(ByRef $avArray, $aRowArray, $nRow = '')
    Local $number_of_columns = UBound($avArray, 2), $number_of_rows = UBound($avArray), $nSize = 0
    If $number_of_columns < (UBound($aRowArray)) Then $number_of_columns = UBound($aRowArray)
    If $nRow > $number_of_rows - 1 Then
        SetError(2)
        Return (2)
    EndIf
    If $number_of_columns < UBound($aRowArray) Then $number_of_columns = UBound($aRowArray)
    ReDim $avArray[$number_of_rows ][$number_of_columns]
    For $c = 1 To UBound($avArray, 2) - 1
        If Not ($c > UBound($aRowArray) - 1) Then
            $avArray[$nRow][$c] = $aRowArray[$c]
        EndIf
    Next
    SetError(0)
    Return (0)
EndFunc   ;==>_ArrayReplace2DRow



Func _GetFirstArrItem($Arr, $dir=0)
    if $dir then ; Search from Array End
        for $p = UBound($Arr)-1 to 1 step -1
            if not ($Arr[$p][0] == "") then 
                ExitLoop
            endif
            if $p = 0 then return false
        next
        return $p
    else ; Search from Array Start
        for $p = 0 to UBound($Arr)-1
            if $Arr[$p][0] == "" then 
                ExitLoop
            endif
            if $p = UBound($Arr)-1 then return false
        next
        return $p
    Endif
EndFunc



Func showtimerdiff($line,byref $timer2,$str="")
    ConsoleWrite("!----:"&round(timerdiff($timer2)) &"       "&$str& @CRLF) 
    $timer2= TimerInit()
EndFunc

Func showtimerdiffsub($line,byref $timer3,$str="")
    local $dim = UBound($timersub)-1
    for $u = 0 to $dim
        if $timersub[$u][0] = $line then ExitLoop
        if $u = $dim then 
            if $dim > 0 or $timersub[0][0] <> "" then redim $timersub[$dim+2][3]
            $dim = UBound($timersub)-1
            $timersub[$dim][0] = $line
            $timersub[$dim][1] = TimerDiff($timer3)
            $timersub[$dim][2] = $str
            $timer3= TimerInit()
            return
        endif
    next
    $timersub[$u][1] += timerdiff($timer3)
    $timer3= TimerInit()
EndFunc

Func showtimerdiffsubfinish($str="")
    local $dim = UBound($timersub)-1
    ConsoleWrite("!                ----<"&$str&" >---- "&@CRLF)
    for $o = 0 to UBound($timersub)-1
        ConsoleWrite("-                   ----"&round($timersub[$o][1])&", "&$timersub[$o][2] & @CRLF)
    next
EndFunc


;# ------------------------------------------------------------------------
;# get distance between two positions
;# ------------------------------------------------------------------------
func GetD($x1,$z1,$y1,$x2,$z2,$y2)

    local $diffVec[3] = [0.0, 0.0, 0.0]
    $diffVec[0] = floor($x1-$x2)
    $diffVec[1] = floor($z1-$z2)
    $diffVec[2] = floor($y1-$y2)

    $dist = floor(sqrt($diffVec[0] * $diffVec[0] + $diffVec[1] * $diffVec[1] + $diffVec[2] * $diffVec[2])*10)/10
    return $dist
EndFunc
;   # ------------------------------------------------------------------------

Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

Share this post


Link to post
Share on other sites
Siao

Why are you using these _StringSplit2 and __ArrayReplace2DRow functions?

Doesn't look optimal at all. Cut down all the redundant actions.

Func GetPlayerInfo()
    $Playerdata = StringSplit($recvArr[$e], chr(13))
    Dim $Playerinfo[64][46] ; clear current Player info
    For $i = 1 To $Playerdata[0]
        $tmpline = StringSplit($Playerdata[$i], Chr(9))
        If UBound($tmpline) = 47 Then ; if row valid
            For $j = 1 To $tmpline[0]
                $Playerinfo[$i-1][$j-1] = $tmpline[$j]
            Next
        Else
            ConsoleWrite("Error: Corrupt Player info data at Zeile: "&$i & ""&UBound($tmpline)&""& @CRLF)
            ContinueLoop
        EndIf
    Next
EndFunc

Now if the above is too slow for your needs, then yes, you would need to ditch all this 2D array approach for something more robust.


"be smart, drink your wine"

Share this post


Link to post
Share on other sites
weaponx

I would just like to say that since I am a big Battlefield 2 player I really hope this isn't a hack, I don't support game hacking of any kind. If its just for stats tracking, thats different.

Edited by weaponx

Share this post


Link to post
Share on other sites
qsek

@ weaponx: believe me. It not any kind of that, its rather the opposite: A very useful program for the Game. I sent you a pm.

@ Siao: Wow, i already thought in this direction, but never came to try it out. Thats really a min 15% cutoff both to ms and CPU usage. Thank you very much!

But there are still 30% to 35% left to optimize, i think this is caused mainly from the eventrows part and the Get Distance part of the Code.

I have to build a $Plevent variabe cause for later evaluating i need fast acces to both the actual Playerinfo and to the Event that happened to player.

So instaed of using:

if $LastPlayerinfo[$i][4]+0 > $Playerinfo[$i][4]+0 and $LastPlayerinfo[$i][10] = 1 then ;....oÝ÷ Ú(î²ÚnµëÞ¯'¯z{[zÜz}7èùZÉêâúÝ7趬´ùZÉêâú"Ú±êZ­«^ºÚÉ«­¢+Ø$%½ÈÀÌØí襸ÀÌØíÙ¹ÑɽÝÌ($$$ÀÌØíA±Ù¹ÑlÀÌØí¥ulÀÌØíétôÅÕ½ÐìÅÕ½Ðì($$%¥ÀÌØí1ÍÑA±åÉ¥¹½lÀÌØí¥ulÀÌØíétôôÀÌØíA±åÉ¥¹½lÀÌØí¥ulÀÌØíétÑ¡¸
½¹Ñ¥¹Õ1½½À($$%¥MÑÉ¥¹%Í%¹Ð ÀÌØí1ÍÑA±åÉ¥¹½lÀÌØí¥ulÀÌØíét¤½ÈMÑÉ¥¹%Í%¹Ð ÀÌØíA±åÉ¥¹½lÀÌØí¥ulÀÌØíét¤Ñ¡¸($$$%¥ÀÌØí1ÍÑA±åÉ¥¹½lÀÌØí¥ulÀÌØíét¬ÀÐìÀÌØíA±åÉ¥¹½lÀÌØí¥ulÀÌØíét¬ÀQ¡¸($$$$$ÀÌØíA±Ù¹ÑlÀÌØí¥ulÀÌØíétôÅÕ½Ðì´ÄÅÕ½Ðìì
¡¹½Ý¸Ä´´ØÈìÀ($$$%±Í¥ÀÌØí1ÍÑA±åÉ¥¹½lÀÌØí¥ulÀÌØíét¬À±ÐìÀÌØíA±åÉ¥¹½lÀÌØí¥ulÀÌØíét¬ÀQ¡¸($$$$$ÀÌØíA±Ù¹ÑlÀÌØí¥ulÀÌØíétôÅÕ½ÐìÄÅÕ½Ðìì
¡¹UÀÀ´´ØÈìÄ($$$%¹¥($$%±Í($$$%¥ÀÌØí1ÍÑA±åÉ¥¹½lÀÌØí¥ulÀÌØíét±ÐìÐìÀÌØíA±åÉ¥¹½lÀÌØí¥ulÀÌØíétQ¡¸ÀÌØíA±Ù¹ÑlÀÌØí¥ulÀÌØíétôÅÕ½ÐìÈÅÕ½ÐììMÑÉ¥¹
¡¹(($$%¹¥($%¹áÐoÝ÷ ٩ݶ§Æ§ºÇ­+®¶²y²û-jצz{ljëh×6if $Plevent[$i][4] and $LastPlayerinfo[$i][10] = 1 then ;....

Ok i now it look like too much afford for just one if statement, but i have a lot! of these statements and variable checking and processing, so this is very reasonable to do.

For the Get distance Part im not sure what causes so much CPU, it could be the StringSplit you have to do for every coodinate, or the GetD function which could be a bit math intensive.

I have no idea how to optimize that...

Now if the above is too slow for your needs, then yes, you would need to ditch all this 2D array approach for something more robust.

What would this "robust" solution be?

Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

Share this post


Link to post
Share on other sites
qsek

Wow i think i found the main reason why it is so slow.

I really wondered because on my original script i get really high times even at short sections like "Loop, New Player.."

With the same playercount i get 10 ms for this sections on this script in the forum,

and 60 ms on my original script. And now i know why:

Just add includes to this script!

The more includes, the more time it will take to execute even the simplest if statement.

I wonder why it is like that. Is it a matter of the amount Variables which are loaded to memory or are this special functions in the includes itself?

Maybe using a dll, or COM Objects. The thing i dont understand is: Why have such things so much impact on all script execution?

So, which options i have or scripts i could use to get rid of unnecessary includedata?


Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

Share this post


Link to post
Share on other sites
martin

Wow i think i found the main reason why it is so slow.

I really wondered because on my original script i get really high times even at short sections like "Loop, New Player.."

With the same playercount i get 10 ms for this sections on this script in the forum,

and 60 ms on my original script. And now i know why:

Just add includes to this script!

The more includes, the more time it will take to execute even the simplest if statement.

I wonder why it is like that. Is it a matter of the amount Variables which are loaded to memory or are this special functions in the includes itself?

Maybe using a dll, or COM Objects. The thing i dont understand is: Why have such things so much impact on all script execution?

So, which options i have or scripts i could use to get rid of unnecessary includedata?

Do you mean that just adding an include without otherwise changing your code will change the speed? Can you give an example?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
qsek

Do you mean that just adding an include without otherwise changing your code will change the speed? Can you give an example?

This is just the same code like i posted before, but with more includes (comment out those you dont have)

The timings goes on some sections up to 500%

#include <WindowsConstants.au3>
#include <UpDownConstants.au3>
#include <StaticConstants.au3>
#include <DateTimeConstants.au3>
#include <ListViewConstants.au3>

#include "MD5.AU3"
;~ #include <Prospeed.AU3>
#include <Array.au3>
#include <File.au3>
#Include <Date.au3>
#include <String.au3>
#include <Array2D.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#Include <GuiListBox.au3>
#Include <GuiComboBox.au3>
#Include <GuiImageList.au3>
#Include <GuiListView.au3>


;~ ProcessSetPriority(@AutoItPID,4) ; for better results with timers

Opt("GUIOnEventMode",1)


; ### Populating an Array with 10 Input Strings
dim $recvArr[10]
dim $DataType[46] = [0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1,0,0,2,0,3,0,2,0,0,0]

for $z = 0 to 9
    $String = ""
    for $r = 0 to 63
        for $t = 0 to 45
            if $t = 0 then
                $String &= $r&@TAB
                ContinueLoop
            Endif
            switch $DataType[$t]
                case 0 ; Int
                    $String &= Random(0,1,1)&@TAB
                case 1 ; float
                    $String &= Random(0,1,1)&@TAB
                case 2 ; String
                    for $p = 0 to Random(5,10,1)
                        $String &= chr(Random(65,122,1))
                    next
                    $String &= @TAB
                case 3 ; 3D coordiantes
                    $String &= Random(-100,100)&","&Random(-100,100)&","&Random(-100,100)&@TAB
            EndSwitch

            if $t = 45 then
                $String = StringTrimRight($String,1)
                if $r <> 63 then $String &= @CR
            Endif
        next
    next
    $recvArr[$z] = $String
next
; ###


$e = 0

$tick = @SEC


Dim $Plinfo[64][30]
Dim $Playerinfo[64][46] ; this is the Array i want to have fast access to
$LastPlayerinfo = $Playerinfo ; this is the data of the previous second, that i want to compare

$timer2= TimerInit() ; timer for whole Loop

$timer3= TimerInit() ; Timer for using inside of Loop

; #### Main Loop ####
While 1
    Sleep(20)
    If $tick <> @SEC then
;~   Times(-2)
       
        GetPlayerInfo()
       
            $timer2= TimerInit()
            global $timersub[1][3]
            $timer3= TimerInit()
        UpdatePlayerPos()
        UpdatePlayerPos() ; represents all the stuff code

        showtimerdiff(@ScriptLineNumber,$timer2,"UpdatePlayerPos(Total)")
            showtimerdiffsubfinish("Sub UpdatePlayerPos")
           
    Endif
    $tick = @SEC
wend
; ####


Func GetPlayerInfo()

    $timer2= TimerInit()
   
    $Playerdata = StringSplit($recvArr[$e], chr(13))
   
;~  _ArrayDisplay($Playerdata)
    Dim $Playerinfo[64][46] ; clear current Player info

    For $i = 1 To $Playerdata[0] ; Zeile

        if not $Playerdata[$i] then ContinueLoop

        $tmpline = _StringSplit2($Playerdata[$i], Chr(9))
;~   _ArrayDisplay($tmpline)
        If UBound($tmpline) = 46 Then ; if row valid

            __ArrayReplace2DRow ($Playerinfo, $tmpline, $tmpline[0]+0) ; refresh Row/PlayerSlot

;~    $Playerinfo[$tmpline[0]] = $tmpline
        Else
            ConsoleWrite("Error: Corrupt Player info data at Zeile: "&$i & ""&UBound($tmpline)&""& @CRLF)
            ContinueLoop
        EndIf
    Next
   
;~  _ArrayDisplay($Playerinfo)

    $e += 1 ; move to the next Stringdata
    if $e = 3 then $e = 0
       
    showtimerdiff(@ScriptLineNumber,$timer2,"GetPlayerinfo")
EndFunc

Func UpdatePlayerPos()

    for $i = 0 to 63


        $timer3= TimerInit()

        ;###################################################################
        ;############ Loop, New Player and Connecting Issues ###############
        if Not $LastPlayerinfo[$i][1] then
            if Not $Playerinfo[$i][1] then
                ContinueLoop; no player
            elseif $Playerinfo[$i][4] = "0" then
;~     ConsoleWrite("Player connecting: " & $Playerinfo[$i][1] & "(Slot " & $i & ")"&$i)
                ; ~ stuff~
                ContinueLoop
            endif   
        elseif not $Playerinfo[$i][4] then
            ConsoleWrite("Still connecting..." & @CRLF)
            ContinueLoop
        elseif $LastPlayerinfo[$i][1] And not $Playerinfo[$i][1] then
            ConsoleWrite("Disconnected" & @CRLF)
            ; ~ stuff~
            $LastPlayerinfo = $Playerinfo
            ContinueLoop
        Endif

        showtimerdiffsub(@ScriptLineNumber,$timer3,"Loop, New Player..")

        dim $Plviol[64][50]
        $Plviol[$i][5] = ""
        $Plviol[$i][10] = ""
        $Plviol[$i][15] = ""
        $Plviol[$i][20] = ""
        $Plviol[$i][25] = ""
        $Plviol[$i][30] = ""
        $Plviol[$i][31] = ""
       
        global $ttsent  = 0
        global $consend = 0
        dim $AlivePlcount[5]
        $AlivePlcount[3] = $AlivePlcount[1]
        $AlivePlcount[4] = $AlivePlcount[2]
        $AlivePlcount[1] = 0
        $AlivePlcount[2] = 0
        local $fragskillsRound = 0
        local $warned = 0
        global $Plevent[64][41] ; Reset the Events
        global $Plfragevents[64][12] ; reset the Frag Infos
               
        If $Playerinfo[$i][4] = 1 and $LastPlayerinfo[$i][4] == "0" and $Playerinfo[$i][8] = "0" Then ; Player finished loading but still dead
            if $Plinfo[$i][1] then
                if $ttsent then ConsoleWrite($Playerinfo[$i][42] & @CRLF)
            else
;~     ConsoleWrite("Player "&$Playerinfo[$i][1]&" connected."&$i)
            Endif

;~    ConsoleWrite("Spieler "&$Playerinfo[$i][1]&" hat fertig geladen, ist noch tot")

            $LastPlayerinfo[$i][4] = $Playerinfo[$i][4]

        Endif

        if $LastPlayerinfo[$i][1] = "" and $Playerinfo[$i][1] then  ; New Player loaded
;~    ConsoleWrite("Slot init:"&$i & @CRLF)
            $Plfragevents[$i][5] = 1
            $Plinfo[$i][13] = TimerInit() ; Start zone Timer
            Switch $Playerinfo[$i][33]
                case 8
                    $Plinfo[$i][11] = 0
                case 0,2,4,6
                    $Plinfo[$i][11] = 1
                case 1,3
                    $Plinfo[$i][11] = 2
                case 5,7,11
                    $Plinfo[$i][11] = 3
            endswitch
;~    SetSprite($i)
        Endif
        showtimerdiffsub(@ScriptLineNumber,$timer3,"finished loading")
       

        ;#############################################
        ;############ Create Playerevents ############
       
        Dim $Eventrows[30] = ["0","1","2","4","8","9","12","14","15","16","19","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40"]

        for $z in $Eventrows
            $Plevent[$i][$z] = ""
            if $LastPlayerinfo[$i][$z] == $Playerinfo[$i][$z] then ContinueLoop
           
            if StringIsInt($LastPlayerinfo[$i][$z]) or StringIsInt($Playerinfo[$i][$z]) then
                if $LastPlayerinfo[$i][$z]+0 > $Playerinfo[$i][$z]+0 Then
                    $Plevent[$i][$z] = "-1" ; Changed Down 1 --> 0
                elseif $LastPlayerinfo[$i][$z]+0 < $Playerinfo[$i][$z]+0 Then
                    $Plevent[$i][$z] = "1" ;  Changed Up   0 --> 1
                Endif
            else
                if $LastPlayerinfo[$i][$z] <> $Playerinfo[$i][$z] Then $Plevent[$i][$z] = "2" ; String Change
            Endif

            if not $LastPlayerinfo[$i][$z] and $Playerinfo[$i][$z] then ; New Player has no events
                $Plevent[$i][$z] = ""
            Endif
           
        next
        showtimerdiffsub(@ScriptLineNumber,$timer3,"eventrows")

        Dim $tmp2 = 0
        for $u = 0 to Ubound($Plevent,2)-1
            if $Plevent[$i][$u] then
                $tmp2 = 1
                ExitLoop ; check if there was an event
            endif
        next
       
        showtimerdiffsub(@ScriptLineNumber,$timer3,"check if event")
        if not ($Playerinfo[$i][8] = 0 or $Playerinfo[$i][9] = 1) then ; Player alive
            $AlivePlcount[$Playerinfo[$i][2]] += 1
        Endif
       
        if not $tmp2 and $LastPlayerinfo[$i][1] <> "" then
            ContinueLoop ; Nothing Changed
        Endif

        ; ########### Corrections ###########
        if ($Plevent[$i][8] = 1 or $Plevent[$i][9] = -1) and $Plevent[$i][40]= "" and $LastPlayerinfo[$i][9] <> 1 then
            if $Plevent[$i][8] = 1 then $Playerinfo[$i][8] = "0" ; Reset
            if $Plevent[$i][9] = -1 then $Playerinfo[$i][9] = "1" ; Reset
            ConsoleWrite($Playerinfo[$i][1] & " has spawned, but no poschange  --> next time")
            for $t = 0 to 44
                if $t = 40 then Continueloop
                $Playerinfo[$i][$t] = $LastPlayerinfo[$i][$t]
            next
        Endif
       
; ~ stuff~

; ~ stuff~

; ~ stuff~



        showtimerdiffsub(@ScriptLineNumber,$timer3,"Corrections and stuff")
       
       
       
       
        ; ##########################################################
        ; ###################### Get Distance ######################
        $Flagdist = ""
       
        if not ($Playerinfo[$i][8] = 0 or $Playerinfo[$i][9] = 1) then ; Player alive
            $zo = ""
            $lastzo = $Plviol[$i][0]
            if $Playerinfo[$i][40] then ; Flags

                for $w = 0 to 5 ; Get the distance to certain players
                    if $Playerinfo[$w][40] = "" then ContinueLoop ; no player

                    $tmpPlayerPos = StringSplit($Playerinfo[$i][40], ",")
                    $tmpLastPlayerPos = StringSplit($Playerinfo[$w][40], ",")
                    $tmpdist = 50
                    $tmpdist = GetD($tmpPlayerPos[1],$tmpPlayerPos[2],$tmpPlayerPos[3],$tmpLastPlayerPos[1],$tmpLastPlayerPos[2],$tmpLastPlayerPos[3])
                    if not $Flagdist then
                        $Flagdist = $tmpdist
                    elseif $tmpdist < $Flagdist Then ; find the smallest Distance
                        $Flagdist = $tmpdist
                    endif
                    ContinueLoop
                next
               
               
                for $w = 0 to 63 ; Get the distance to every other player
                    if $Playerinfo[$w][40] = "" then ContinueLoop ; no player

                    $tmpPlayerPos = StringSplit($Playerinfo[$i][40], ",")
                    $tmpLastPlayerPos = StringSplit($Playerinfo[$w][40], ",")
                    $tmpdist = 50
                    $tmpdist = GetD($tmpPlayerPos[1],$tmpPlayerPos[2],$tmpPlayerPos[3],$tmpLastPlayerPos[1],$tmpLastPlayerPos[2],$tmpLastPlayerPos[3])
                    if not $Flagdist then
                        $Flagdist = $tmpdist
                    elseif $tmpdist < $Flagdist Then ; find the smallest Distance
                        $Flagdist = $tmpdist
                    endif
                    ContinueLoop
                next
               
               
                $tdif = TimerDiff($Plinfo[$i][13])
               
                ; ############ Camping #################
                if  ($Plevent[$i][2]=1) then
               
                ; ~ lots of stuff~
               
                ; ~ lots of stuff~
               
                ; ~ lots of stuff~
               
                elseif 1 then
                    if $Flagdist < 20 then ; closer than 10 meters
                        $Plviol[$i][0] = -1
                    else
                        $Plviol[$i][0] = ""
                    endif
                endif
            Endif


            $Plinfo[$i][15] = $Flagdist

            if $lastzo <> $Plviol[$i][0] or ($zo > 1 and $Plinfo[$i][13] = "") then
                $Plinfo[$i][13] = TimerInit()
            endif
           
        endif
        showtimerdiffsub(@ScriptLineNumber,$timer3,"get distance")
       
    ;###################################################
    ;############ Player Game Events ###################

                       
                ; ~ lots of stuff~
               
                ; ~ lots of stuff~
               
                ; ~ lots of stuff~
               


        showtimerdiffsub(@ScriptLineNumber,$timer3,"Gameevents")
       
    next
    $LastPlayerinfo = $Playerinfo
EndFunc







Func _StringSplit2($sStr, $sSepF, $iFlag = 0)
    Local $sTmp = $sStr, $arFileF[1] = [$sStr], $iPos, $iPos1, $sLenSep = StringLen($sSepF), $iCaseSens = 1
    If $sSepF = "" Then ;handle empty splitter separator
        $iPos = 2
        $sTmp = StringLeft($sStr, 1)
        ; if Sep has more than 1 character, we must first check for ;split the Separator into individual characters
    ElseIf Not $iFlag And $sLenSep > 1 Then ;maybe we should use RegExp
        ; check the first character as separator, to find likely $iPos candidate
        Local $aSep = StringSplit($sSepF, "", 1) ;split the Separator into individual characters
        $iPos = StringInStr($sTmp, $aSep[1], $iCaseSens)
        $sTmp = StringLeft($sTmp, $iPos - 1) ;keep as short as possible
        For $c = 2 To UBound($aSep) - 1; loop through the rest of the separators in case any are sooner
            $iPos1 = StringInStr($sTmp, $aSep[$c ], $iCaseSens)
            If $iPos1 And $iPos1 < $iPos Then ;must be found, and < $iPos
                $iPos = $iPos1
                $sTmp = StringLeft($sTmp, $iPos - 1) ;keep as short as possible
            EndIf
        Next
    Else ;if $iFlag=1 or only 1 character, above not needed
        If $sLenSep > 1 Then $iCaseSens = 0 ;stringsplit is NOT case-sensitive if more than 1 char in separator, used as 1
        $iPos = StringInStr($sStr, $sSepF, $iCaseSens)
        $sTmp = StringLeft($sStr, $iPos - 1)
    EndIf
    If Not $iPos Then Return SetError(@error, 0, $arFileF)
    If Not $iFlag And $sLenSep Then $sLenSep = 1 ;change length for single char separators of "0" $iFlag
    $sStr = StringMid($sStr, $iPos + $sLenSep)
    $arFileF = StringSplit($sStr, $sSepF, $iFlag)
    $arFileF[0] = $sTmp
    Return SetError(0, 0, $arFileF);$arFileF
EndFunc   ;==>_StringSplit2


Func __ArrayReplace2DRow(ByRef $avArray, $aRowArray, $nRow = '')
    Local $number_of_columns = UBound($avArray, 2), $number_of_rows = UBound($avArray), $nSize = 0
    If $number_of_columns < (UBound($aRowArray)) Then $number_of_columns = UBound($aRowArray)
    If $nRow > $number_of_rows - 1 Then
        SetError(2)
        Return (2)
    EndIf
    If $number_of_columns < UBound($aRowArray) Then $number_of_columns = UBound($aRowArray)
    ReDim $avArray[$number_of_rows ][$number_of_columns]
    For $c = 1 To UBound($avArray, 2) - 1
        If Not ($c > UBound($aRowArray) - 1) Then
            $avArray[$nRow][$c] = $aRowArray[$c]
        EndIf
    Next
    SetError(0)
    Return (0)
EndFunc   ;==>_ArrayReplace2DRow



Func _GetFirstArrItem($Arr, $dir=0)
    if $dir then ; Search from Array End
        for $p = UBound($Arr)-1 to 1 step -1
            if not ($Arr[$p][0] == "") then
                ExitLoop
            endif
            if $p = 0 then return false
        next
        return $p
    else ; Search from Array Start
        for $p = 0 to UBound($Arr)-1
            if $Arr[$p][0] == "" then
                ExitLoop
            endif
            if $p = UBound($Arr)-1 then return false
        next
        return $p
    Endif
EndFunc



Func showtimerdiff($line,byref $timer2,$str="")
    ConsoleWrite("!----:"&round(timerdiff($timer2)) &"       "&$str& @CRLF)
    $timer2= TimerInit()
EndFunc

Func showtimerdiffsub($line,byref $timer3,$str="")
    local $dim = UBound($timersub)-1
    for $u = 0 to $dim
        if $timersub[$u][0] = $line then ExitLoop
        if $u = $dim then
            if $dim > 0 or $timersub[0][0] <> "" then redim $timersub[$dim+2][3]
            $dim = UBound($timersub)-1
            $timersub[$dim][0] = $line
            $timersub[$dim][1] = TimerDiff($timer3)
            $timersub[$dim][2] = $str
            $timer3= TimerInit()
            return
        endif
    next
    $timersub[$u][1] += timerdiff($timer3)
    $timer3= TimerInit()
EndFunc

Func showtimerdiffsubfinish($str="")
    local $dim = UBound($timersub)-1
    ConsoleWrite("!                ----<"&$str&" >---- "&@CRLF)
    for $o = 0 to UBound($timersub)-1
        ConsoleWrite("-                   ----"&round($timersub[$o][1])&", "&$timersub[$o][2] & @CRLF)
    next
EndFunc


;# ------------------------------------------------------------------------
;# get distance between two positions
;# ------------------------------------------------------------------------
func GetD($x1,$z1,$y1,$x2,$z2,$y2)

    local $diffVec[3] = [0.0, 0.0, 0.0]
    $diffVec[0] = floor($x1-$x2)
    $diffVec[1] = floor($z1-$z2)
    $diffVec[2] = floor($y1-$y2)

    $dist = floor(sqrt($diffVec[0] * $diffVec[0] + $diffVec[1] * $diffVec[1] + $diffVec[2] * $diffVec[2])*10)/10
    return $dist
EndFunc
;   # ------------------------------------------------------------------------
Edited by qsek

Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite

Share this post


Link to post
Share on other sites
martin

This is just the same code like i posted before, but with more includes (comment out those you dont have)

The timings goes on some sections up to 500%

I couldn't run your script but I tried a simple test

#include <WindowsConstants.au3>
#include <UpDownConstants.au3>
#include <StaticConstants.au3>
#include <DateTimeConstants.au3>
#include <ListViewConstants.au3>
;#include "MD5.AU3"
;~ #include <Prospeed.AU3>
#include <Array.au3>
#include <File.au3>;[[[[
#Include <Date.au3>
#include <String.au3>
;#include <Array2D.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#Include <GuiListBox.au3>
#Include <GuiComboBox.au3>
#Include <GuiImageList.au3>
#Include <GuiListView.au3>
#ce
Global $ww[60][60]
$b=0

$a = TimerInit()
For $n = 1 To 59
    For $p = 1 To 59
        If $ww[$n][$p] = 9 Then $b=1
    Next
Next
ConsoleWrite(TimerDiff($a) & @CRLF)

The time taken for me varied a lot. Maybe by a factor of 6 if instead of the If $ww.. I said $ww[$n][$p] = 9.

But if I remove the comments around the includes then the times are much better!

I tried placing the declaration for $ww at the beginning before the includes and I couldn't see it made any difference. It looks to me like maybe it depends on a lot of things that are in the scroipt but I certainly don't understand what. Anyway, for this example adding includes has the reverse effect to what you have experienced.

EDIT: If I compile the script then it does seem to be slightly faster if I comment out the includes. Were you compiling your script?

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×