Jump to content

Autoit too many CPU usage problem


Recommended Posts

When many words are added
It works very slowly
Is there a solution for this?

It also uses a lot of CPU!

6f43848452be4d5cb5a2c625febbf9d5.png

 

Spoiler
#include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Dim $aEditRead
$Form1 = GUICreate("Form1", 581, 352, 192, 125)
$Edit1 = GUICtrlCreateEdit("", 24, 32, 145, 225)
GUICtrlSetData(-1, "Autoit" & @CRLF & "autoit" & @CRLF & "autoitscript"  & @CRLF & "autoitscript" & @CRLF & "123" & @CRLF & "123" & @CRLF & "Autoitscript" & @CRLF & "autoitscript.com" & @CRLF & "autoitscript.coM" & @CRLF & "Autoitscript" & @CRLF & "123a" & @CRLF & "123A" & @CRLF & "AutoitscripT")
$Edit2 = GUICtrlCreateEdit("" & @CRLF, 184, 32, 145, 225, BitOR($ES_MULTILINE, $ES_AUTOVSCROLL, $WS_VSCROLL))
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("Delete similar", 24, 296, 70, 33)
$Label2 = GUICtrlCreateLabel("", 208, 272, 46, 17)
$Button2 = GUICtrlCreateButton("Copy", 200, 296, 75, 33)
$Edit3 = GUICtrlCreateEdit("" & @CRLF, 344, 32, 185, 225, BitOR($ES_MULTILINE, $ES_AUTOVSCROLL, $WS_VSCROLL))
$Label1 = GUICtrlCreateLabel("Similar ones", 368, 272, 97, 24)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            _deletesimilar()
    EndSwitch
WEnd

Func _deletesimilar()
    $aEditRead = StringSplit(StringStripCR(GUICtrlRead($Edit1)), @LF,2)
    $aUniques=_ArrayUnique($aEditRead, 0, 0, 1)
    $aUniques2=_ArrayUnique($aEditRead)
    For $i = 1 To UBound($aUniques) - 1
        $aPos = _ArrayFindAll($aEditRead, $aUniques[$i], 0, 0, 1)
        If UBound($aPos) > 1 Then GUICtrlSetData($Edit2, $aUniques[$i] & @CRLF, 1)
    Next
    GUICtrlSetData($Label2, "Deleted")

    Dim $aSimilar[UBound($aEditRead)]
    $c = 0
    For $i = 1 To UBound($aUniques2) - 1
        $aPos = _ArrayFindAll($aEditRead, $aUniques2[$i])
        If UBound($aPos) > 0 Then
            For $j = 0 To UBound($aPos) - 1
                $aSimilar[$c] = $aEditRead[$aPos[$j]]
                $c += 1
            Next
        EndIf
    Next
    ReDim $aSimilar[$c]
    $aUniques3=_ArrayUnique($aSimilar, 0, 0, 1)
    _ArraySort($aUniques3)
    For $i = 1 to UBound($aUniques3) - 1
        GUICtrlSetData($Edit3, $aUniques3[$i] & @CRLF, 1)
    Next
EndFunc

 

 

Link to comment
Share on other sites

  • Moderators

When are you seeing it use CPU; when you are entering one of the functions or all of the time? Even spamming the "Delete Similar" button I could not drive the CPU usage above 8%.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

youtuber,

You want to operate on 50 K+ (478K bytes) entries using edit controls and array udf's.  Even after you add guictrlsetlimit statements to get the edit controls to load you will have terrible response time.  You need to use a DB or possibly a dictionary object as your access mechanism.  If you define what you are trying to do we can help with that.

I tried your code like this...

#include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Dim $aEditRead
$Form1 = GUICreate("Form1", 581, 352, 192, 125)
$Edit1 = GUICtrlCreateEdit("", 24, 32, 145, 225)
guictrlsetlimit($Edit1,1000000000)  ; <------  increase limit
;GUICtrlSetData(-1, "Autoit" & @CRLF & "autoit" & @CRLF & "autoitscript"  & @CRLF & "autoitscript" & @CRLF & "123" & @CRLF & "123" & @CRLF & "Autoitscript" & @CRLF & "autoitscript.com" & @CRLF & "autoitscript.coM" & @CRLF & "Autoitscript" & @CRLF & "123a" & @CRLF & "123A" & @CRLF & "AutoitscripT")
$Edit2 = GUICtrlCreateEdit("" & @CRLF, 184, 32, 145, 225, BitOR($ES_MULTILINE, $ES_AUTOVSCROLL, $WS_VSCROLL))
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("Delete similar", 24, 296, 70, 33)
$Label2 = GUICtrlCreateLabel("", 208, 272, 46, 17)
$Button2 = GUICtrlCreateButton("Copy", 200, 296, 75, 33)
$Edit3 = GUICtrlCreateEdit("" & @CRLF, 344, 32, 185, 225, BitOR($ES_MULTILINE, $ES_AUTOVSCROLL, $WS_VSCROLL))
$Label1 = GUICtrlCreateLabel("Similar ones", 368, 272, 97, 24)
GUISetState(@SW_SHOW)

; load edit control

local $adict = stringregexp(fileread(@scriptdir & '\dict.txt'),'.*\R',3)

for $1 = 0 to ubound($adict) - 1
    guictrlsetdata($edit1,$adict[$1],1)
next

; end load edit control

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            _deletesimilar()
    EndSwitch
WEnd

Func _deletesimilar()
    $aEditRead = StringSplit(StringStripCR(GUICtrlRead($Edit1)), @LF,2)
    $aUniques=_ArrayUnique($aEditRead, 0, 0, 1)
    $aUniques2=_ArrayUnique($aEditRead)
    For $i = 1 To UBound($aUniques) - 1
        $aPos = _ArrayFindAll($aEditRead, $aUniques[$i], 0, 0, 1)
        If UBound($aPos) > 1 Then GUICtrlSetData($Edit2, $aUniques[$i] & @CRLF, 1)
    Next
    GUICtrlSetData($Label2, "Deleted")

    Dim $aSimilar[UBound($aEditRead)]
    $c = 0
    For $i = 1 To UBound($aUniques2) - 1
        $aPos = _ArrayFindAll($aEditRead, $aUniques2[$i])
        If UBound($aPos) > 0 Then
            For $j = 0 To UBound($aPos) - 1
                $aSimilar[$c] = $aEditRead[$aPos[$j]]
                $c += 1
            Next
        EndIf
    Next
    ReDim $aSimilar[$c]
    $aUniques3=_ArrayUnique($aSimilar, 0, 0, 1)
    _ArraySort($aUniques3)
    For $i = 1 to UBound($aUniques3) - 1
        GUICtrlSetData($Edit3, $aUniques3[$i] & @CRLF, 1)
    Next
EndFunc

and the response is terrible. 

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...