Page 1 of 1

Parameter reading sequence (ReadPreference...)

Posted: Tue Dec 13, 2022 7:48 am
by AZJIO
If I have 100 parameters and I need to read them into the program, should I read the parameters in the same order they appear in the ini file? Or, regardless of the order of the parameters, is each searched from the beginning of the group name? In the worst case, the file will be read 100 times, at best 1 time.

Re: Parameter reading sequence (ReadPreference...)

Posted: Tue Dec 13, 2022 8:38 am
by juergenkulow

Code: Select all

; Create file with 100 Varis
CreatePreferences(GetTemporaryDirectory()+"test.ini")
PreferenceGroup("Test")
For i=1 To 100
  WritePreferenceQuad("Vari"+Str(i),i)
Next
ClosePreferences()

Code: Select all

; Read 100 Varis 
OpenPreferences(GetTemporaryDirectory()+"test.ini")
PreferenceGroup("Test")
Dim Field(100)
Start=ElapsedMilliseconds()
;For i=100 To 1 Step -1
For i=1 To 100
  Field(i)=ReadPreferenceQuad("Vari"+Str(i),0)
  ;Debug Field(i)
Next
Debug Str(ElapsedMilliseconds()-Start)+" ms"
; 0 ms For i=1 To 100
; 0 ms For i=100 To 1 Step -1

Re: Parameter reading sequence (ReadPreference...)

Posted: Tue Dec 13, 2022 9:17 am
by AZJIO
0.580 ms.
I initially thought that the number would be higher, so I wanted to arrange the parameters in order so that when it starts looking for the next parameter, it would be on the next line from the current position in the ini file section.

Code: Select all

DisableDebugger

Define maxfreq.q, a.q, b.q, time$
QueryPerformanceFrequency_(@maxfreq)
maxfreq / 1000
time$ = ""
QueryPerformanceCounter_(@a.q)

OpenPreferences(GetTemporaryDirectory()+"test.ini")
PreferenceGroup("Test")
Dim Field(100)
For i=100 To 1 Step -1
; For i=1 To 100
  Field(i)=ReadPreferenceQuad("Vari"+Str(i),0)
Next
QueryPerformanceCounter_(@b.q)
time$ + RSet(StrD((b - a) / maxfreq, 3), 8) + " - ms" + #LF$
MessageRequester("", time$)
If you comment out the loop, it turns out that almost all the time is spent opening the file. Since the work with the file is cached, the search in the data block occurs in memory.

0.071 ms.

Code: Select all

DisableDebugger
Dim Field(100)

Define maxfreq.q, a.q, b.q, time$
OpenPreferences(GetTemporaryDirectory()+"test.ini")
PreferenceGroup("Test")

QueryPerformanceFrequency_(@maxfreq)
maxfreq / 1000
time$ = ""
QueryPerformanceCounter_(@a.q)

For i=100 To 1 Step -1
; For i=1 To 100
  Field(i)=ReadPreferenceQuad("Vari"+Str(i),0)
Next

QueryPerformanceCounter_(@b.q)
time$ + RSet(StrD((b - a) / maxfreq, 3), 8) + " - ms" + #LF$
MessageRequester("", time$)

Re: Parameter reading sequence (ReadPreference...)

Posted: Tue Dec 13, 2022 9:43 am
by mk-soft
I am not longer use preferences and change to XML

Link :viewtopic.php?t=74233

Re: Parameter reading sequence (ReadPreference...)

Posted: Wed Dec 14, 2022 9:55 am
by AZJIO
What are the reasons for this choice?

Is it easier to work with these functions? ExtractXMLStructure, InsertXMLStructure...

For complex projects it is more convenient, there is an export of lists, arrays, maps. I'll have to experiment too.