My weird results so far, in order of speed from the fastest to the slowest, are the following:
(time elapsed for doing the same action looped for 1 million times)
PixelSearch - 8.16
PixelGetColor - 14.87
GDI+ code by Linear Spoon - 20.24
PixelGetColor Alt - 29.32
PixelGetColor Slow - 36.30
PixelSearch Fast - 46.89
GDI+ by me - more than 15 minutes...
(no differences detected between RGB and BGR PixelSearch options, PixelGetColor was untested)
Pretty much everyone says that the Gdip library is 3 times faster than the default PixelSearch so I must be doing something terrible in my code...
Here are the benchmark codes I have used for:
(please note, Continue should be used WHEN POSSIBLE instead of Sleep -1, benchmarks are done faster that way)
PixelGetColor test
Code: Select all
#NoEnv
#KeyHistory 0
#MaxThreads 255
#MaxMem 4095
#MaxThreadsBuffer On
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
ListLines Off
Process, Priority, , R
SetTitleMatchMode fast
SetBatchLines, -1
SetKeyDelay, -1, -1, -1
SetMouseDelay, -1
SetWinDelay, -1
SetControlDelay, -1
SetDefaultMouseSpeed, 0
QPC()
{
Static QPCLAST, QPCNOW, QPCFREQ
if not QPCFREQ
if not DllCall("QueryPerformanceFrequency", "Int64 *", QPCFREQ)
return "Fail QPF"
QPCLAST=%QPCNOW%
if not DllCall("QueryPerformanceCounter", "Int64 *", QPCNOW)
return "Fail QPC"
return (QPCNOW-QPCLAST)/QPCFREQ
}
LastTickCount=%A_TickCount%
QPC()
loop 1000000
{
pixelgetcolor, test, 100, 100
if (test=0xFFFFFF)
sleep -1
}
msgbox, % "TickCount`n" A_TickCount-LastTickCount "`n`nQueryPerformanceCounter`n" QPC()
Code: Select all
#NoEnv
#KeyHistory 0
#MaxThreads 255
#MaxMem 4095
#MaxThreadsBuffer On
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
ListLines Off
Process, Priority, , R
SetTitleMatchMode fast
SetBatchLines, -1
SetKeyDelay, -1, -1, -1
SetMouseDelay, -1
SetWinDelay, -1
SetControlDelay, -1
SetDefaultMouseSpeed, 0
QPC()
{
Static QPCLAST, QPCNOW, QPCFREQ
if not QPCFREQ
if not DllCall("QueryPerformanceFrequency", "Int64 *", QPCFREQ)
return "Fail QPF"
QPCLAST=%QPCNOW%
if not DllCall("QueryPerformanceCounter", "Int64 *", QPCNOW)
return "Fail QPC"
return (QPCNOW-QPCLAST)/QPCFREQ
}
LastTickCount=%A_TickCount%
QPC()
loop 1000000
{
pixelsearch, , , 100, 100, 100, 100, 0xFFFFFF
if errorlevel = 0
sleep -1
}
msgbox, % "TickCount`n" A_TickCount-LastTickCount "`n`nQueryPerformanceCounter`n" QPC()
Code: Select all
#include gdip.ahk
PixelSearch(x, y, color)
{
pToken := GDIP_StartUp()
pBitMap := GDIP_BitmapFromScreen()
ARGB := GDIP_GetPixel(pBitMap, x, y)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
If (ARGB = color)
Return true
Else
Return false
}
#NoEnv
#KeyHistory 0
#MaxThreads 255
#MaxMem 4095
#MaxThreadsBuffer On
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
ListLines Off
Process, Priority, , R
SetTitleMatchMode fast
SetBatchLines, -1
SetKeyDelay, -1, -1, -1
SetMouseDelay, -1
SetWinDelay, -1
SetControlDelay, -1
SetDefaultMouseSpeed, 0
QPC()
{
Static QPCLAST, QPCNOW, QPCFREQ
if not QPCFREQ
if not DllCall("QueryPerformanceFrequency", "Int64 *", QPCFREQ)
return "Fail QPF"
QPCLAST=%QPCNOW%
if not DllCall("QueryPerformanceCounter", "Int64 *", QPCNOW)
return "Fail QPC"
return (QPCNOW-QPCLAST)/QPCFREQ
}
LastTickCount=%A_TickCount%
QPC()
loop 1000000
{
If PixelSearch(100,100,4294967295)
sleep -1
}
msgbox, % "TickCount`n" A_TickCount-LastTickCount "`n`nQueryPerformanceCounter`n" QPC()
My request is: can anyone help me to create a responsive code using the Gdip library?
EDIT:
Spoiler