Does IniWrite rewrite the whole file every time?
Posted: 10 Aug 2018, 07:07
Because I got like 50 IniWrites and I am thinking FileAppend would be faster.
Let's help each other out
https://www.autohotkey.com/boards/
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=53766
Code: Select all
ListLines OFF ;Doesn't display the script lines most recently executed, thus improving performance
;#KeyHistory 0 ;KeyHistory is required by A_PriorKey, so don't disable it!
#InstallKeybdHook ;Ensures that hotkeys are more responsive
#InstallMouseHook ;Ensures that hotkeys are more responsive
#UseHook ON ;Ensures that hotkeys are more responsive
#SingleInstance FORCE
#NoEnv ;Avoids checking empty variables to see if they are environment variables
#Warn UseEnv
#MaxThreadsBuffer OFF ;Causes some or all hotkeys to buffer rather than ignore keypresses when their #MaxThreadsPerHotkey limit has been reached
#HotkeyInterval 90000000
#MaxHotkeysPerInterval 90000000 ;Along with #HotkeyInterval, specifies the rate of hotkey activations beyond which a warning dialog will be displayed.
#MaxThreadsPerHotkey 255 ;This is the max
#MaxThreads 255 ;This is the max
#MaxMem 128 ;Default is 64 megabytes max variable size
Process Priority,,High ;Sets the script's priority to High, it is advised that you never set it to "Real Time"
DetectHiddenWindows ON
SetTitleMatchMode 3 ;A window's title must exactly match WinTitle to be a match
SetBatchLines -1 ;Determines how fast the script will run, a value of -1 allows it to use up to 100% of a CPU core, however, Autohotkey can only use one CPU core - https://autohotkey.com/board/topic/22889-using-more-than-50-of-the-cpu/?p=262950
SetKeyDelay -1,-1
SetMouseDelay -1
SetDefaultMouseSpeed 0
SetWinDelay 0 ;Although a delay of -1 (no delay at all) is allowed, it is recommended that at least 0 be used, to increase confidence that the script will run correctly even when the CPU is under load
SetControlDelay -1 ;Sets the delay that will occur after each control-modifying command.
SetWorkingDir % A_ScriptDir
;^ Before adding these settings, saving 30 keys with IniWrite would consistently spike up to 30ms / 100000 computations, I am not sure which setting is responsible for fixing that, nor do I care.
Random,RandomValue,0,999
IniValues=
(
[General]
Entry1=837
Entry2=837
Entry3=837
Entry4=837
Entry5=837
Entry6=837
Entry7=837
Entry8=837
Entry9=837
Entry10=837
Entry11=837
Entry12=837
Entry13=837
Entry14=837
Entry15=837
Entry16=837
Entry17=837
Entry18=837
Entry19=837
Entry20=837
Entry21=837
Entry22=837
Entry23=837
Entry24=837
Entry25=837
Entry26=837
Entry27=837
Entry28=837
Entry29=837
Entry30=837
)
Test()
Loop 30
IniWrite,%RandomValue%,Testing IniWrite Speed.ini,General,Entry%A_Index%
Test("Msgbox")
/*
Test()
FileDelete,Testing IniWrite Speed2.ini
FileAppend,%IniValues%,Testing IniWrite Speed2.ini
Test("Msgbox")
*/
ExitApp
Test(Message:="Tooltip") ;by Ħakito
{
Static StartTime
Static LastResult
iF StartTime
{
DllCall("QueryPerformanceCounter", "Int64*", EndTime) ;A_TickCount and MSec could also be used instead
DllCall("QueryPerformanceFrequency", "Int64*", Frequency) ;The number of cpu cycles per second
Result:=EndTime-StartTime " total computations`nWhich took " (EndTime-StartTime)/(Frequency/1000) "ms" LastResult
LastResult:="`n`nLast result: " EndTime-StartTime " & " (EndTime-StartTime)/(Frequency/1000)
StartTime:=""
iF Message=Tooltip
Tooltip % Result
else iF Message=Msgbox
Msgbox % Result
return EndTime-StartTime
}
else DllCall("QueryPerformanceCounter","Int64*",StartTime)
}
F5::Reload
Code: Select all
IniValues=
(
Entry1=837
Entry2=837
Entry3=837
Entry4=837
Entry5=837
Entry6=837
Entry7=837
Entry8=837
Entry9=837
Entry10=837
Entry11=837
Entry12=837
Entry13=837
Entry14=837
Entry15=837
Entry16=837
Entry17=837
Entry18=837
Entry19=837
Entry20=837
Entry21=837
Entry22=837
Entry23=837
Entry24=837
Entry25=837
Entry26=837
Entry27=837
Entry28=837
Entry29=837
Entry30=837
)
IniWrite % IniValues, % A_Desktop . "\~tmp.ini", General
Oh nice, didn't know it could be done like that!Flipeador wrote:Well, in your test it is obvious that using FileAppend you write everything at once, and on the contrary, you are calling IniWrite 30 times.
You can write everything at once:Code: Select all
IniValues= ( Entry1=837 Entry2=837 Entry3=837 Entry4=837 Entry5=837 Entry6=837 Entry7=837 Entry8=837 Entry9=837 Entry10=837 Entry11=837 Entry12=837 Entry13=837 Entry14=837 Entry15=837 Entry16=837 Entry17=837 Entry18=837 Entry19=837 Entry20=837 Entry21=837 Entry22=837 Entry23=837 Entry24=837 Entry25=837 Entry26=837 Entry27=837 Entry28=837 Entry29=837 Entry30=837 ) IniWrite % IniValues, % A_Desktop . "\~tmp.ini", General