Parameter reading sequence (ReadPreference...)

Just starting out? Need help? Post your questions and find answers here.
AZJIO
Addict
Addict
Posts: 2171
Joined: Sun May 14, 2017 1:48 am

Parameter reading sequence (ReadPreference...)

Post 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.
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: Parameter reading sequence (ReadPreference...)

Post 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
AZJIO
Addict
Addict
Posts: 2171
Joined: Sun May 14, 2017 1:48 am

Re: Parameter reading sequence (ReadPreference...)

Post 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$)
User avatar
mk-soft
Always Here
Always Here
Posts: 6237
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Parameter reading sequence (ReadPreference...)

Post by mk-soft »

I am not longer use preferences and change to XML

Link :viewtopic.php?t=74233
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
AZJIO
Addict
Addict
Posts: 2171
Joined: Sun May 14, 2017 1:48 am

Re: Parameter reading sequence (ReadPreference...)

Post 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.
Post Reply