Sign in to follow this  
Followers 0
WeMartiansAreFriendly

Much Faster _GUICtrlListView_XXX functions

9 posts in this topic

#1 ·  Posted (edited)

I've always thought some of the _GUICtrlListView_xxx functions were kind of slow, so after playing around, I've noticed a HUGE speed performance when using hWnd instead Control IDs.

Here's an example where I simply rewrote "_GUICtrlListView_DeleteAllItems" to utilize GUICtrlGetHandle()..

I created 1200 items, then deleted them here's what I got (in milliseconds)

speed for original: 551.475676377864

speed for modified: 9.26290911275036

Hmm... :)

Example

#include <GuiListView.au3>

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>


$Form2 = GUICreate("FEEL THE SPEED", 413, 298, 303, 219)
$ListView1 = GUICtrlCreateListView("Test1|Test2", 8, 16, 394, 206)
$Button1 = GUICtrlCreateButton("Create", 16, 232, 75, 25, 0)
$Button2 = GUICtrlCreateButton("Delete (with Original UDF)", 176, 232, 171, 25, 0)
$Button3 = GUICtrlCreateButton("Delete (with Modified UDF)", 176, 264, 171, 25, 0)



GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            For $i = 1 to 1200
                GUICtrlCreateListViewItem("Test1" & $i & "|Test2" & $i, $ListView1)
            Next
        Case $Button2
            $timer = TimerInit()
            _GUICtrlListView_DeleteAllItems_ORIGINAL($ListView1)
            ConsoleWrite("speed for original: :" & TimerDiff($timer) &@lf)
        Case $Button3
            $timer = TimerInit()
            _GUICtrlListView_DeleteAllItems_MODIFIED($ListView1)
            ConsoleWrite("speed for modified: " & TimerDiff($timer) &@lf)

    EndSwitch
WEnd



; orginal (included with Autoit)
Func _GUICtrlListView_DeleteAllItems_ORIGINAL($hWnd)
    If $Debug_LV Then _GUICtrlListView_ValidateClassName($hWnd)
    Local $ctrlID, $index
    If _GUICtrlListView_GetItemCount($hWnd) == 0 Then Return True
    If IsHWnd($hWnd) Then
        Return _SendMessage($hWnd, $LVM_DELETEALLITEMS) <> 0
    Else
        ; this part seems to be SLOOOOOOOOOOW
        For $index = _GUICtrlListView_GetItemCount($hWnd) - 1 To 0 Step -1
            $ctrlID = _GUICtrlListView_GetItemParam($hWnd, $index)
            If $ctrlID Then GUICtrlDelete($ctrlID)
        Next
        If _GUICtrlListView_GetItemCount($hWnd) == 0 Then Return True
    EndIf
    Return False
EndFunc   ;==>_GUICtrlListView_DeleteAllItems

; modified!
;You could also just use: _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView))
Func _GUICtrlListView_DeleteAllItems_MODIFIED($hWnd)
    If $Debug_LV Then _GUICtrlListView_ValidateClassName($hWnd)
    Local $ctrlID, $index
    
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    
    If _GUICtrlListView_GetItemCount($hWnd) == 0 Then Return True

    Return _SendMessage($hWnd, $LVM_DELETEALLITEMS) <> 0
EndFunc   ;==>_GUICtrlListView_DeleteAllItems
Edited by mrRevoked

Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

Share this post


Link to post
Share on other sites



WOW, that is a significant difference.. Thanx!

Share this post


Link to post
Share on other sites

i've constated it when i've used paulia functions and then autoit conversions of them => i've reprogrammed all of the function to make it fast.

maybe a paramter would be better in those function instead of let the function choose if it's a hwnd or not.


-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]

Share this post


Link to post
Share on other sites

I use _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView)) for simplicify (not for perfomance) too.

But in this case all control IDs (for listview items created by GUICtrlCreateListviewItem) remain undeleted (memory leak).

So this is not exactly right concept.

Share this post


Link to post
Share on other sites

this is the case for all of the control functions that verify the hwnd of the parameter.


-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I use _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView)) for simplicify (not for perfomance) too.

But in this case all control IDs (for listview items created by GUICtrlCreateListviewItem) remain undeleted (memory leak).

So this is not exactly right concept.

Well, thanks for pointing that out, you're absolutely right, the memory usage keeps growing.

I've written somewhat of an alternative to GUICtrlCreateListviewItem.

Some strange observations, using a handle instead of an ID for _GUICtrlListView_CreateItem() is significantly slower while the opposite is true for _GUICtrlListView_DeleteAllItems. :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

$Form2 = GUICreate("Example", 413, 298, 303, 219)
$ListView = GUICtrlCreateListView("Test1|Test2", 8, 16, 394, 206)
$Button1 = GUICtrlCreateButton("Create", 16, 232, 75, 25, 0)
$Button2 = GUICtrlCreateButton("Delete All", 176, 232, 171, 25, 0)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $timer = TimerInit()
            For $i = 1 to 1200
                _GUICtrlListView_CreateItem($ListView, "Test1" & $i &"|"& "Test2"& $i)
            Next
            ConsoleWrite("creation speed: :" & TimerDiff($timer) &@lf)
        Case $Button2
            $hListView = GUICtrlGetHandle($ListView); get the handle to the list view
            $timer = TimerInit()
            _GUICtrlListView_DeleteAllItems($hListView)
            ConsoleWrite("deletion speed: :" & TimerDiff($timer) &@lf)
    EndSwitch
WEnd

; #FUNCTION# ====================================================================================================

================
; Name...........: _GUICtrlListView_CreateItem()
; Description ...: Creates a list view item with subitems
; Syntax.........: _GUICtrlListView_CreateItem($hListView, $sItem)
; Parameters ....: $hListView   - Handle to the control
;                 $sItemText    - Item text (string delimited)
; Return values .:  Success - Item Index
;               Failure @error
;                       1 - Item delimiter failed
;                       2 - Failed to Add item
;                       3 - Failed to Add sub item
; Author ........: mrRevoked
; Remarks .......:
; Related .......: _GUICtrlListView_AddItem, _GUICtrlListView_AddSubItem
; Link ..........;
; Example .......; Yes
; ====================================================================================================


Func _GUICtrlListView_CreateItem($hListView, $sItemText)
    Local $sDelim = Opt('GUIDataSeparatorChar')
    Local $aItem = StringSplit($sItemText, $sDelim)
    If $aItem[0] < 1 Then Return SetError(1, 0, 0)
    Local $iIndex = _GUICtrlListView_AddItem($hListView, $aItem[1])
    If $iIndex < 0 Then Return SetError(2, 0, 0)
    For $i = 2 To $aItem[0]
        $iSubItem = _GUICtrlListView_AddSubItem($hListView, $iIndex, $aItem[$i], $i - 1)
        If $iSubItem = False Then Return SetError(3, 0, 0); don't want to be stuck inside a loop of fail.
    Next
    Return $iIndex
EndFunc  ;_GUICtrlListView_CreateItem
Edited by mrRevoked

Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0