For example, the word "hello" would be split into:
hel
hell
ell
ello
I'm wondering why, despite AHK using internal arrays, the script takes an extremely long time (see attached gif below) and, as you can see in the gif below, it only consumes 3% of my CPU and 5.5MB of RAM. Since I have a pretty powerful system, why can't AHK utilize more resources and complete this task 1000x faster?
My system:
Operating System
Windows 10 Pro 64-bit
CPU
Intel Core i9 10900K @ 3.70GHz, 3696 Mhz, 10 Core(s), 20 Logical Processor(s)
RAM
Corsair Vengeance RGB Pro 64 GB (2 x 32 GB) DDR4-3200 CL16
Motherboard
Gigabyte Z590 AORUS MASTER (U3E1)
Graphics
LG ULTRAWIDE (3840x1600@60Hz)
Intel UHD Graphics 630 (Gigabyte)
2047MB NVIDIA GeForce RTX 3080
Here is the gif:
Here is the code:
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#Include <GlobalsKDP>
xlApp := XL_Handle(1)
MyPath := GlobalsKDP_GetGridsWorkingPath()
XL_Speedup(xlApp,0)
XL_Select_Sheet(xlApp,"MAIN-WORDS")
if xlApp.Range(rang_Word_tblMainWords).Find("*",,,,,2)
xlApp.Range(rang_Word_tblMainWords).Sort(xlApp.Range(rang_Word_tblMainWords),,,,,,,1) ; with Header
_RangeSize := xlApp.Range(rang_Word_tblMainWords).rows.Count()
xlApp.Range(rang_Word_tblMainWords).Copy
ClipWait, 1
global MainWords := Clipboard
xlApp.Application.CutCopyMode := False
SplitArray := 0
;=========================
;// NOTE FOR PROGRESS BAR
;=========================
Gui, Add, Text, xm w360 vProgressWord, Checking Word...`nPlease Wait
Gui, Add, Progress, xm w300 h20 vProgressBar -Smooth
Gui, Add, Button, yp-1 hp+2 xp+305 w60 gButtonCancel, Cancel
Gui, Add, Text, xm w360 vProgressText
Gui, Show,, Splitting Words...
Loop, parse, MainWords, `n, `r
{
String := A_LoopField
StrLen := StrLen(String)
CurrOrgWordPos := A_Index
Loop, % StrLen
{
CurrStr := SubStr(String, A_Index)
CurrStrLen := StrLen(CurrStr)
Loop, % CurrStrLen
{
;=========================
;// NOTE FOR PROGRESS BAR
;=========================
GuiControl,, ProgressWord, Splitting word: %CurrOrgWordPos% out of %_RangeSize%: %String%`nSplit Word: %CurrStr%
Percent := Floor( (CurrOrgWordPos / _RangeSize) * 100 )
GuiControl,, ProgressBar, %Percent%
GuiControl,, ProgressText, %Percent%`% Complete
Loop, % CurrStrLen
{
UseStr:=SubStr(CurrStr, 1, A_Index)
if ((StrLen(UseStr) >= 3) and (IsInMainWords(UseStr)=false))
FinalString .= UseStr "`n"
}
}
}
}
NewString:=EX_RemoveDuplicates(FinalString, SplitArray)
msgbox % "Total split words created after removing dups: " SplitArray "."
StartTime := A_TickCount
XL_Select_Sheet(xlApp,"SPLIT-WORDS")
Clipboard := NewString
ClipWait, 1
xlApp.Range(rang_Word_tblSplitWords).ClearContents
xlApp.Range("A2").PasteSpecial()
xlApp.Range(rang_Word_tblSplitWords).Sort(xlApp.Range("A2"),,,,,,,1)
ElapsedTime := ConvertMSToMinSec(A_TickCount - StartTime)
MsgBox, %ElapsedTime% have elapsed.
XL_Speedup(xlApp,1)
msgbox % "Finished spliting words."
ConvertMSToMinSec(ms)
{
return, floor((ms / 1000) / 60) " minutes "
. floor(mod((ms / 1000), 60)) " seconds "
. floor((mod((ms / 1000), 60) - sec) * 1000) " mseconds "
}
IsInMainWords(str)
{
Loop, Parse, MainWords, `n, `r
{
if (str = A_LoopField)
return true
}
return false
}
GetOutOfHere:
GuiClose:
GuiEscape:
ButtonCancel:
CancelCopy := true
Gui, Destroy
ExitMe:
ExitApp