Jangal Posted August 24, 2020 Posted August 24, 2020 (edited) Hello friends This app is slow How to increase its speed? #include <Array.au3> #include <StringConstants.au3> #include <File.au3> #include <String.au3> Global $aWord[][2] = [[1, "google"],[2,"hello"]] Global $sFileName = @ScriptDir & "\1.txt" ; 2MB Text File Local $sFileRead = FileRead($sFileName) Local $res = StringRegExp($sFileRead, "(*UCP)\b[\pL\d]{2,}", 3) _ArrayDisplay($res) for $sWord in $res $iIndex = _ArraySearch($aWord, $sWord, 0, 0, 0, 0, 1, 2) ;MsgBox(0,0,$iIndex) if $iIndex == -1 Then Local $aFill = [[0,$sWord]] _ArrayAdd($aWord,$aFill) ; Else $aWord[$iIndex][0] +=1 EndIf Next _ArrayDisplay($aWord) 1.txt Edited August 24, 2020 by Jangal 1.txt added
Developers Jos Posted August 24, 2020 Developers Posted August 24, 2020 Why are you posting all these images? AutoIt3 is single threaded so will only run on one core of the CPU so will max use 25%. Post your script code (not image) in a CODEBLOCK (<>) so we can have a proper look/test with that to see what can be done to make that faster. Jos Jangal 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Jangal Posted August 24, 2020 Author Posted August 24, 2020 #include <Array.au3> #include <StringConstants.au3> #include <File.au3> #include <String.au3> Global $aWord[][2] = [[1, "google"],[2,"hello"]] Global $sFileName = @ScriptDir & "\1.txt" ; 2MB Text File Local $sFileRead = FileRead($sFileName) Local $res = StringRegExp($sFileRead, "(*UCP)\b[\pL\d]{2,}", 3) _ArrayDisplay($res) for $sWord in $res $iIndex = _ArraySearch($aWord, $sWord, 0, 0, 0, 0, 1, 2) ;MsgBox(0,0,$iIndex) if $iIndex == -1 Then Local $aFill = [[0,$sWord]] _ArrayAdd($aWord,$aFill) ; Else $aWord[$iIndex][0] +=1 EndIf Next _ArrayDisplay($aWord) This script is fast on short strings But in the attached file it takes hours
Developers Jos Posted August 24, 2020 Developers Posted August 24, 2020 Care to also explain what it is you want to accomplish with the script and what it is for, so we understand? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
seadoggie01 Posted August 24, 2020 Posted August 24, 2020 (edited) So you're looking to make a script that creates a list of words and the number of times they appear in the document, right? Right now, if a word appears 5 times in your document, you search for that word 5 times. Also, you begin your search at the beginning of the array each time, you only need to search after the current index word. Possibly check out the implementation of _ArrayUnique in Array.au3 to get an idea of how to get started. (Note that this doesn't keep track of how many times each word appears) Edited August 24, 2020 by seadoggie01 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
Jangal Posted August 24, 2020 Author Posted August 24, 2020 (edited) @seadoggie01 I started autoit to start learning programming I will consider other methods Thanks Edited August 24, 2020 by Jangal
Nine Posted August 24, 2020 Posted August 24, 2020 I'd say scripting dictionary. It is the perfect situation to use it. Here to start you up : #include <Constants.au3> #include <Array.au3> Opt ("MustDeclareVars", 1) Local $t = TimerInit() Local $oDict = ObjCreate("Scripting.Dictionary") Local $aWord = FileReadToArray("1.txt") Local $iCount = @extended, $p For $i = 0 To $iCount - 1 If Not StringRegExp ($aWord[$i], "(*UCP)\b[\pL\d]{2,}") Then ContinueLoop $p = $aWord[$i] If $oDict.Exists($p) Then $oDict.Item($p) = $oDict.Item($p) + 1 Else $oDict.Add($p, 1) EndIf Next ConsoleWrite($iCount & "/" & $oDict.Count & @CRLF) Local $aCount[$oDict.Count][2] $p = 0 For $vKeys In $oDict $aCount[$p][0] = $vKeys $aCount[$p][1] = $oDict.item($vKeys) $p += 1 Next MsgBox($MB_SYSTEMMODAL, "", $p & "/" & TimerDiff($t)) Taking me 4.5 secs overall with your 1.txt file. Musashi, pixelsearch, Jangal and 1 other 3 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now