if u run this script, which bypasses ahk and creates GUIs using
CreateWindowEx(), ull see that the more u create, the longer it takes for windows to create them. on my computer, the first GUI takes 2ms and the 10000th - about 80ms
if u run ur ComboBox benchmark at any point during, ull also see that it takes variably longer to add the items
why is that? can windows not keep up with updating its internal window tracking structures? is it because there are too many windowProcs to call into? who knows.
Code: Select all
#Requires AutoHotkey v2.0-a137
Stats := Gui('+AlwaysOnTop')
Stats.Add('Text', , 'A_Index:')
Index := Stats.Add('Text', 'w100 yp')
Stats.Add('Text', 'xm', 'Total:')
Total := Stats.Add('Text', 'w100 yp')
Stats.Add('Text', 'xm', 'Per Window:')
PerWindow := Stats.Add('Text', 'w100 yp')
Stats.Show()
DllCall('QueryPerformanceFrequency', 'Int64*', &frequency := 0)
GUIs := []
DllCall('QueryPerformanceCounter', 'Int64*', &t0 := 0)
Loop 10000
{
DllCall('QueryPerformanceCounter', 'Int64*', &t1 := 0)
hwnd := makeGui()
DllCall('QueryPerformanceCounter', 'Int64*', &t2 := 0)
Index.Text := A_Index
Total.Text := toMs(t0, t2)
PerWindow.Text := toMs(t1, t2)
GUIs.Push(hwnd) ; play with these
; DllCall('DestroyWindow', 'Ptr', hwnd) ; play with these
}
MsgBox 'script has finished. OK to exit'
toMs(start, end) => Round(((end - start) * 1000) / frequency) ' ms'
makeGui() {
static wc
if !IsSet(wc)
{
; typedef struct tagWNDCLASSW {
; 0 UINT style;
; 8 WNDPROC lpfnWndProc;
; 16 int cbClsExtra;
; 20 int cbWndExtra;
; 24 HINSTANCE hInstance;
; 32 HICON hIcon;
; 40 HCURSOR hCursor;
; 48 HBRUSH hbrBackground;
; 56 LPWSTR lpszMenuName;
; 64 LPWSTR lpszClassName;
; }
wc := Buffer(72, 0)
wndProc(hwnd, msg, wparam, lparam) => true
static lpfnWndProc := CallbackCreate(wndProc)
NumPut('Ptr', lpfnWndProc, wc, 8) ; lpfnWndProc
static hInstance := DllCall('GetModuleHandle', 'Ptr', 0, 'Ptr')
NumPut('Ptr', hInstance, wc, 24) ; hInstance
static className := 'randomgui'
NumPut('Ptr', StrPtr(className), wc, 64) ; lpszClassName
DllCall('RegisterClass', 'Ptr', wc)
}
static WS_POPUP := 0x80000000
static WS_CAPTION := 0xC00000
static WS_SYSMENU := 0x80000
static WS_MINIMIZEBOX := 0x20000
static styles := WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX
return DllCall('CreateWindowEx',
'UInt', 0, ; dwExStyle
'Str', className, ; lpClassName
'Str', 'random title', ; lpWindowName
'UInt', styles, ; dwStyle
'Int', 0, ; X
'Int', 0, ; Y
'Int', 100, ; nWidth
'Int', 100, ; nHeight
'Ptr', 0, ; hWndParent
'Ptr', 0, ; hMenu
'Ptr', hInstance, ; hInstance
'Ptr', 0) ; lpParam
}