#include <Array.au3>
Opt('MustDeclareVars', 1)
Global $sFile = 'Test_Script.exe', $sTitle = StringLeft($sFile, StringInStr($sFile, '.', 0, -1) - 1), $hWnd, $iPid, $hProc, $aRes, $iTimer, $iRes, $hWin, _
$iCount = 10, $aResult[7][$iCount + 2] = [['ProcessExists'],['WinGetHandle'],['FindWindowW'],['WinExists'],['IsWindow'],['IsHWnd'],['GetExitCodeProcess']], _
$aMin[2] = [100], $aMax[2]
$iPid = Run(@ScriptDir & '\' & $sFile)
If Not $iPid Then Exit 1
$hWnd = WinWait('[Title:' & $sTitle & ';Class:AutoIt v3]', '', 3)
If Not $hWnd Then Exit 2
$aRes = DllCall('kernel32.dll', 'handle', 'OpenProcess', 'dword', 0x1000, 'bool', 0, 'dword', $iPid)
;~ $PROCESS_QUERY_LIMITED_INFORMATION = = 0x1000 ;Win Vista +
;~ $PROCESS_QUERY_INFORMATION = 0x0400 ;WinXP
If (@error) Or (Not $aRes[0]) Then Exit 3
$hProc = $aRes[0]
For $i = 1 To $iCount
Sleep(1000)
$iTimer = TimerInit()
$iRes = ProcessExists($iPid)
$aResult[0][$i] = Round(TimerDiff($iTimer), 3)
ConsoleWrite('ProcessExists: ' & $aResult[0][$i] & @TAB & $iRes & @LF)
Sleep(1000)
$iTimer = TimerInit()
$hWin = WinGetHandle('[Title:' & $sTitle & ';Class:AutoIt v3]')
$aResult[1][$i] = Round(TimerDiff($iTimer), 3)
ConsoleWrite('WinGetHandle: ' & $aResult[1][$i] & @TAB & $hWin & @LF)
Sleep(1000)
$iTimer = TimerInit()
$aRes = DllCall('user32.dll', 'hwnd', 'FindWindowW', 'wstr', 'AutoIt v3', 'wstr', $sTitle)
$aResult[2][$i] = Round(TimerDiff($iTimer), 3)
ConsoleWrite('FindWindowW: ' & $aResult[2][$i] & @TAB & $aRes[0] & @LF)
Sleep(1000)
$iTimer = TimerInit()
$iRes = WinExists($hWnd)
$aResult[3][$i] = Round(TimerDiff($iTimer), 3)
ConsoleWrite('WinExists: ' & $aResult[3][$i] & @TAB & $iRes & @LF)
Sleep(1000)
$iTimer = TimerInit()
$aRes = DllCall('user32.dll', 'int', 'IsWindow', 'hwnd', $hWnd)
$aResult[4][$i] = Round(TimerDiff($iTimer), 3)
ConsoleWrite('IsWindow: ' & $aResult[4][$i] & @TAB & $aRes[0] & @LF)
Sleep(1000)
$iTimer = TimerInit()
$iRes = IsHWnd($hWnd)
$aResult[5][$i] = Round(TimerDiff($iTimer), 3)
ConsoleWrite('IsHWnd: ' & $aResult[5][$i] & @TAB & $iRes & @LF)
Sleep(1000)
$iTimer = TimerInit()
$aRes = DllCall('kernel32.dll', 'int', 'GetExitCodeProcess', 'ptr', $hProc, 'dword*', 0)
$aResult[6][$i] = Round(TimerDiff($iTimer), 3)
ConsoleWrite('GetExitCodeProcess: ' & $aResult[6][$i] & @TAB & $aRes[2] & @LF)
ConsoleWrite('---' & @LF)
Next
DllCall('kernel32.dll', 'bool', 'CloseHandle', 'handle', $hProc)
If ProcessExists($iPid) Then ProcessClose($iPid)
For $i = 0 To 6
For $j = 1 To $iCount
$aResult[$i][$iCount + 1] += $aResult[$i][$j]
Next
$aResult[$i][$iCount + 1] = Round($aResult[$i][$iCount + 1] / $iCount, 3)
If $aResult[$i][$iCount + 1] < $aMin[0] Then
$aMin[0] = $aResult[$i][$iCount + 1]
$aMin[1] = $i
EndIf
If $aResult[$i][$iCount + 1] > $aMax[0] Then
$aMax[0] = $aResult[$i][$iCount + 1]
$aMax[1] = $i
EndIf
Next
ConsoleWrite('Min time func: ' & $aResult[$aMin[1]][0] & @LF)
ConsoleWrite('Max time func: ' & $aResult[$aMax[1]][0] & @LF)
;~ последняя колонка - среднее значение
_ArraySort($aResult, 0, 0, 0, $iCount + 1)
_ArrayDisplay($aResult, 'number of cycles: ' & $iCount)