At first, hey I am Ole and I am new here, hello. My English isn't very neat so forgive me for that.
I wrote a script to run length decode a file which has been loaded into memory. All is working perfect, but, it clocks in at around 17 seconds on my machine. While that wouldn't be such a big problem for someone else, for me it is... I am relatively new to AutoIt so maybe some folks could probably hint me on stuff to read through and things I should really know. The reason behind all this... I just have the idea it could be improven much more.
So here is my script
; Containing byte array struct, created in another function not showed here Global $FILE ; Reserve 2065676 bytes for decoded file Global $DECODED = DllStructCreate("byte[" & 2065676 & "]") ; Well... Func cwln($s) Return ConsoleWrite($s & @lf) EndFunc ; Converts unsigned byte to signed byte Func SByteValue($b) If BitAND($b, 0x80) == 0x80 Then Return -128 + BitXOR($b, 0x80) Else Return $b EndIf EndFunc ; Decode function Func Decode() ; Keep track of several things Local $i = 1, $end = 0, $bVal = 0, $dIndex = 1 Local $bench = TimerInit() ; Start decode loop cwln("Run length decoding...") While $i <= DllStructGetSize($FILE) - 4 ; Initialized to find out if it has a sign bit set $bVal = SByteValue(DllStructGetData($FILE, 1, $i)) ; Decoding If $bVal < 0 Then $end = 1 - $bVal $i += 1 For $j = 1 To $end DllStructSetData($DECODED, 1, DLLStructGetData($FILE, 1, $i), $dIndex) $dIndex += 1 Next Else $end = $bVal + 1 For $k = 1 To $end $i += 1 DllStructSetData($DECODED, 1, DLLStructGetData($FILE, 1, $i), $dIndex) $dIndex += 1 Next EndIf $i += 1 WEnd cwln("Run length decoding ended in " & Ceiling(TimerDiff($bench) / 1000) & " seconds.") EndFunc Decode()
So to clarify on a point... it is working well, no bugs or whatsoever, it just annoys me it is this slow. If something is not clear, tell me, I will try to clarify byebye
Edit: I realize the title looks somewhat imperative... well it isn't meant to be