Moin,
Im Zuge von Optimierungen (ja... aus irgendwelchen Gründen macht es mir Spaß AutoIt für Sachen zu verwenden für die es nicht geeignet ist) habe ich mal wieder ein paar Zeiten gestoppt.
Beim Timing kommen aber aus irgendwelchen Gründen sehr verschiedene Ergebnisse heraus (ich öffne kein Windows Fenster/Msgbox, es ist also nicht der Skriptverlangsamungsbug der damit zusammenhängt).
_01 10770ns +85.2% ->| int32 bitand & bitshift
_02 9712ns +67.1% ->| int32 bitand & bitshift (array als int)
_2A 9528ns +63.9% ->| int32 bitand & bitshift (ternärer operator umgestellt, array als int)
_2B 9115ns +56.8% ->| int32 bitshift & bitand (array als int)
_2C 9067ns +56.0% ->| int32 bitshift & bitand (array als int)
_2D 9376ns +61.3% ->| int32 bitshift & bitand (array als int)
_03 7917ns +36.2% ->| int32 stringoperationen (array als int)
_04 10340ns +77.9% ->| int32 stringoperation für Alpha, rest bitoperationen (array als int)
_05 5905ns +1.6% ->| int32 struct (byte[4] access index, array als int)
_5A 6973ns +19.9% ->| int32 struct (byte;byte;byte;byte access element, array als int)
_5B 5814ns +0.0% ->| int32 struct (byte[4] access index via name, array als int)
Alles anzeigen
_01 6334ns +33.9% ->| int32 bitand & bitshift
_02 5283ns +11.7% ->| int32 bitand & bitshift (array als int)
_2A 5072ns +7.2% ->| int32 bitand & bitshift (ternärer operator umgestellt, array als int)
_2B 4730ns +0.0% ->| int32 bitshift & bitand (array als int)
_2C 4774ns +0.9% ->| int32 bitshift & bitand (array als int)
_2D 4956ns +4.8% ->| int32 bitshift & bitand (array als int)
_03 7871ns +66.4% ->| int32 stringoperationen (array als int)
_04 5884ns +24.4% ->| int32 stringoperation für Alpha, rest bitoperationen (array als int)
_05 5947ns +25.7% ->| int32 struct (byte[4] access index, array als int)
_5A 6954ns +47.0% ->| int32 struct (byte;byte;byte;byte access element, array als int)
_5B 5810ns +22.8% ->| int32 struct (byte[4] access index via name, array als int)
Alles anzeigen
Diese beiden Ergebnisse tauchen beide bei mir reproduzierbar (mit einer gewissen Chance) auf.
Ergebnis 1: Wenn ich im Skript Zeile 82 und 84 auskommentiere taucht vermehrt Ergebnis 1 auf.
Ergebnis 2: Wenn ich im Skript Zeile 82 und 84 einkommentiere taucht vermehrt Ergebnis 2 auf.
(Obwohl diese Zeilen (also eine For-Schleife von 0 bis 0) ansich keinen Einfluss haben sollten)
Der Unterschied ist hier die Ausführungsgeschwindigkeit von BitOperationen, die brauchen plötzlich 2-3x so lange. Alle anderen Operationen laufen ähnlich schnell ab.
Entweder sehe ich meinen offensichtlichen Fehler nicht, oder da ist irgendwas im Gange was ich nicht verstehe...
Deshalb möchte ich in die Runde fragen ob dasselbe Verhalten noch bei anderen Leuten auftritt.
PS: Ich verwende AutoIt Version 3.3.14.5, habe noch keine anderen Versionen getestet.
#include-once
#include <Array.au3>
Global $BENCH[0][4]
Func Add($xFunc, $sDescription = '')
Local $u = UBound($BENCH)
ReDim $BENCH[$u+1][UBound($BENCH, 2)]
$BENCH[$u][0] = $xFunc
$BENCH[$u][1] = 0.0
$BENCH[$u][2] = 0 ; Akkumulierte Millisekunden
$BENCH[$u][3] = $sDescription
EndFunc
Func Timing($n = 150)
Local $a = $BENCH
If $n = 0 Then Return $a
Local $r
For $i = 1 To $n Step 1
$r = Random(0, UBound($a) - 1, 1)
$a[$r][1] += Call($a[$r][0])
$a[$r][2] += 1
Next
For $i = 0 To UBound($a) - 1 Step 1
$a[$i][1] /= $a[$i][2]
Next
Return $a
EndFunc
Func Bench($n = 10)
Local $t = Timing(0), $a[$n][UBound($t)]
For $i = 0 To $n - 1 Step 1
$t = Timing()
For $ii = 0 To UBound($t) - 1 Step 1
$a[$i][$ii] = $t[$ii][1]
Next
Next
Local $aCenter[UBound($t)][UBound($t, 2)], $throwAway = Int(UBound($a)/3)
For $i = 0 To UBound($t) - 1 Step 1
_ArraySort($a, 1, 0, 0, $i)
For $ii = $throwAway To UBound($a) - $throwAway - 1 Step 1
$aCenter[$i][1] += $a[$ii][$i] / (UBound($a) - 2 * $throwAway)
Next
Next
Local $m = $aCenter[0][1]
For $i = 1 To UBound($aCenter) - 1 Step 1
If $m > $aCenter[$i][1] Then $m = $aCenter[$i][1]
Next
ConsoleWrite('Benchmark Result' & @CRLF)
For $i = 0 To UBound($aCenter) - 1 Step 1
$aCenter[$i][0] = FuncName($t[$i][0])
$aCenter[$i][2] = '+' & StringFormat('%.1f', 100 * ($aCenter[$i][1] / $m - 1)) & '%'
$aCenter[$i][1] = StringRight(' ' & StringFormat('%.0f', 1000000.0 * $aCenter[$i][1]), 5) & 'ns'
$aCenter[$i][3] = $t[$i][3]
ConsoleWrite($aCenter[$i][0] & ' ' & $aCenter[$i][1] & ' ' & StringRight(' ' & $aCenter[$i][2], 7) & ' ->| ' & $aCenter[$i][3] & @CRLF)
Next
Return $aCenter
EndFunc
;~ #include "Benchmark.au3"
; Ziel: Zerlege eine Farbe gegeben als int32 (oder uint32, in AutoIt als int64) in ARGB in ein Array[4] als array[i][.] = [A, R, G, B].
; Alle Werte von A, R, G, B sind positive Integer im Bereich [0, 255].
; Bitoperationen in AutoIt sind 32Bit only, es wird also schwer da aus uint32 einen Vorteil zu ziehen (das minus entfällt bei uint)
Add(_01, 'int32 bitand & bitshift')
Add(_02, 'int32 bitand & bitshift (array als int)')
Add(_2A, 'int32 bitand & bitshift (ternärer operator umgestellt, array als int)')
Add(_2B, 'int32 bitshift & bitand (array als int)')
Add(_2C, 'int32 bitshift & bitand (array als int)')
Add(_2D, 'int32 bitshift & bitand (array als int)')
Add(_03, 'int32 stringoperationen (array als int)')
Add(_04, 'int32 stringoperation für Alpha, rest bitoperationen (array als int)')
Add(_05, 'int32 struct (byte[4] access index, array als int)')
Add(_5A, 'int32 struct (byte;byte;byte;byte access element, array als int)')
Add(_5B, 'int32 struct (byte[4] access index via name, array als int)')
;~ For $_ = 0 To 0 Step 1
Bench(10)
;~ Next
Func _01()
Local $c[99], $a[99][4], $t = 0.0, $u = 0.0
For $i = 0 To UBound($c) - 1 Step 1
$c[$i] = BitShift(Random(0, 0xFFFF, 1), -16) + Random(0, 0xFFFF, 1)
Next
$t = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
$a[$i][0] = BitShift(BitAND($c[$i], 0xFF000000), 24) + ($c[$i] < 0 ? 256 : 0)
$a[$i][1] = BitShift(BitAND($c[$i], 0xFF0000), 16)
$a[$i][2] = BitShift(BitAND($c[$i], 0xFF00), 8)
$a[$i][3] = BitAND($c[$i], 0xFF)
Next
$t = TimerDiff($t)
$u = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
Next
$u = TimerDiff($u)
Return ($t - $u)/99.0
EndFunc
Func _02()
Local $c[99], $a[99][4], $t = 0.0, $u = 0.0
For $i = 0 To UBound($c) - 1 Step 1
$c[$i] = BitShift(Random(0, 0xFFFF, 1), -16) + Random(0, 0xFFFF, 1)
$a[$i][0] = 0
$a[$i][1] = 0
$a[$i][2] = 0
$a[$i][3] = 0
Next
$t = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
$a[$i][0] = BitShift(BitAND($c[$i], 0xFF000000), 24) + ($c[$i] < 0 ? 256 : 0)
$a[$i][1] = BitShift(BitAND($c[$i], 0xFF0000), 16)
$a[$i][2] = BitShift(BitAND($c[$i], 0xFF00), 8)
$a[$i][3] = BitAND($c[$i], 0xFF)
Next
$t = TimerDiff($t)
$u = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
Next
$u = TimerDiff($u)
Return ($t - $u)/99.0
EndFunc
Func _2A()
Local $c[99], $a[99][4], $t = 0.0, $u = 0.0
For $i = 0 To UBound($c) - 1 Step 1
$c[$i] = BitShift(Random(0, 0xFFFF, 1), -16) + Random(0, 0xFFFF, 1)
$a[$i][0] = 0
$a[$i][1] = 0
$a[$i][2] = 0
$a[$i][3] = 0
Next
$t = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
$a[$i][0] = $c[$i] > 0 ? BitShift(BitAND($c[$i], 0xFF000000), 24) : BitShift(BitAND($c[$i], 0xFF000000), 24) + 256
$a[$i][1] = BitShift(BitAND($c[$i], 0xFF0000), 16)
$a[$i][2] = BitShift(BitAND($c[$i], 0xFF00), 8)
$a[$i][3] = BitAND($c[$i], 0xFF)
Next
$t = TimerDiff($t)
$u = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
Next
$u = TimerDiff($u)
Return ($t - $u)/99.0
EndFunc
Func _2B()
Local $c[99], $a[99][4], $t = 0.0, $u = 0.0
For $i = 0 To UBound($c) - 1 Step 1
$c[$i] = BitShift(Random(0, 0xFFFF, 1), -16) + Random(0, 0xFFFF, 1)
$a[$i][0] = 0
$a[$i][1] = 0
$a[$i][2] = 0
$a[$i][3] = 0
Next ; Bitand bei Alpha nötig für das Minus
$t = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
$a[$i][0] = BitAND(BitShift($c[$i], 24), 0xFF)
$a[$i][1] = BitAND(BitShift($c[$i], 16), 0xFF)
$a[$i][2] = BitAND(BitShift($c[$i], 8), 0xFF)
$a[$i][3] = BitAND($c[$i], 0xFF)
Next
$t = TimerDiff($t)
$u = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
Next
$u = TimerDiff($u)
Return ($t - $u)/99.0
EndFunc
Func _2C()
Local $c[99], $a[99][4], $t = 0.0, $u = 0.0
For $i = 0 To UBound($c) - 1 Step 1
$c[$i] = BitShift(Random(0, 0xFFFF, 1), -16) + Random(0, 0xFFFF, 1)
$a[$i][0] = 0
$a[$i][1] = 0
$a[$i][2] = 0
$a[$i][3] = 0
Next
$t = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
$a[$i][0] = $c[$i] > 0 ? BitShift($c[$i], 24) : BitShift($c[$i], 24) + 256
$a[$i][1] = BitAND(BitShift($c[$i], 16), 0xFF)
$a[$i][2] = BitAND(BitShift($c[$i], 8), 0xFF)
$a[$i][3] = BitAND($c[$i], 0xFF)
Next
$t = TimerDiff($t)
$u = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
Next
$u = TimerDiff($u)
Return ($t - $u)/99.0
EndFunc
Func _2D()
Local $c[99], $a[99][4], $t = 0.0, $u = 0.0
For $i = 0 To UBound($c) - 1 Step 1
$c[$i] = BitShift(Random(0, 0xFFFF, 1), -16) + Random(0, 0xFFFF, 1)
$a[$i][0] = 0
$a[$i][1] = 0
$a[$i][2] = 0
$a[$i][3] = 0
Next
$t = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
$a[$i][0] = BitShift($c[$i], 24) + ($c[$i] < 0) * 256
$a[$i][1] = BitAND(BitShift($c[$i], 16), 0xFF)
$a[$i][2] = BitAND(BitShift($c[$i], 8), 0xFF)
$a[$i][3] = BitAND($c[$i], 0xFF)
Next
$t = TimerDiff($t)
$u = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
Next
$u = TimerDiff($u)
Return ($t - $u)/99.0
EndFunc
Func _03()
Local $c[99], $a[99][4], $t = 0.0, $u = 0.0
For $i = 0 To UBound($c) - 1 Step 1
$c[$i] = BitShift(Random(0, 0xFFFF, 1), -16) + Random(0, 0xFFFF, 1)
$a[$i][0] = 0
$a[$i][1] = 0
$a[$i][2] = 0
$a[$i][3] = 0
Next
Local $o = ''
$t = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
$o = Hex($c[$i], 8)
$a[$i][0] = Int('0x' & StringLeft($o, 2))
$a[$i][1] = Int('0x' & StringMid($o, 3, 2))
$a[$i][2] = Int('0x' & StringMid($o, 5, 2))
$a[$i][3] = Int('0x' & StringRight($o, 2))
Next
$t = TimerDiff($t)
$u = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
Next
$u = TimerDiff($u)
Return ($t - $u)/99.0
EndFunc
Func _04()
Local $c[99], $a[99][4], $t = 0.0, $u = 0.0
For $i = 0 To UBound($c) - 1 Step 1
$c[$i] = BitShift(Random(0, 0xFFFF, 1), -16) + Random(0, 0xFFFF, 1)
$a[$i][0] = 0
$a[$i][1] = 0
$a[$i][2] = 0
$a[$i][3] = 0
Next
$t = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
$a[$i][0] = Int('0x' & StringLeft(Hex($c[$i], 8), 2))
$a[$i][1] = BitShift(BitAND($c[$i], 0xFF0000), 16)
$a[$i][2] = BitShift(BitAND($c[$i], 0xFF00), 8)
$a[$i][3] = BitAND($c[$i], 0xFF)
Next
$t = TimerDiff($t)
$u = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
Next
$u = TimerDiff($u)
Return ($t - $u)/99.0
EndFunc
Func _05()
Local $c[99], $a[99][4], $t = 0.0, $u = 0.0
For $i = 0 To UBound($c) - 1 Step 1
$c[$i] = BitShift(Random(0, 0xFFFF, 1), -16) + Random(0, 0xFFFF, 1)
$a[$i][0] = 0
$a[$i][1] = 0
$a[$i][2] = 0
$a[$i][3] = 0
Next
Local $p = DllStructCreate('int')
Local $q = DllStructCreate('byte[4]', DllStructGetPtr($p)) ; BGRA Byte order
$t = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
DllStructSetData($p, 1, $c[$i])
$a[$i][0] = DllStructGetData($q, 1, 4)
$a[$i][1] = DllStructGetData($q, 1, 3)
$a[$i][2] = DllStructGetData($q, 1, 2)
$a[$i][3] = DllStructGetData($q, 1, 1)
Next
$t = TimerDiff($t)
$u = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
Next
$u = TimerDiff($u)
Return ($t - $u)/99.0
EndFunc
Func _5A()
Local $c[99], $a[99][4], $t = 0.0, $u = 0.0
For $i = 0 To UBound($c) - 1 Step 1
$c[$i] = BitShift(Random(0, 0xFFFF, 1), -16) + Random(0, 0xFFFF, 1)
$a[$i][0] = 0
$a[$i][1] = 0
$a[$i][2] = 0
$a[$i][3] = 0
Next
Local $p = DllStructCreate('int')
Local $q = DllStructCreate('byte;byte;byte;byte', DllStructGetPtr($p)) ; BGRA Byte order
$t = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
DllStructSetData($p, 1, $c[$i])
$a[$i][0] = DllStructGetData($q, 4)
$a[$i][1] = DllStructGetData($q, 3)
$a[$i][2] = DllStructGetData($q, 2)
$a[$i][3] = DllStructGetData($q, 1)
Next
$t = TimerDiff($t)
$u = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
Next
$u = TimerDiff($u)
Return ($t - $u)/99.0
EndFunc
Func _5B()
Local $c[99], $a[99][4], $t = 0.0, $u = 0.0
For $i = 0 To UBound($c) - 1 Step 1
$c[$i] = BitShift(Random(0, 0xFFFF, 1), -16) + Random(0, 0xFFFF, 1)
$a[$i][0] = 0
$a[$i][1] = 0
$a[$i][2] = 0
$a[$i][3] = 0
Next
Local $p = DllStructCreate('int a')
Local $q = DllStructCreate('byte a[4]', DllStructGetPtr($p)) ; BGRA Byte order
$t = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
$p.a = $c[$i]
$a[$i][0] = $q.a(4)
$a[$i][1] = $q.a(3)
$a[$i][2] = $q.a(2)
$a[$i][3] = $q.a(1)
Next
$t = TimerDiff($t)
$u = TimerInit()
For $i = 0 To UBound($a) - 1 Step 1
Next
$u = TimerDiff($u)
Return ($t - $u)/99.0
EndFunc
Alles anzeigen
lg
M