Parameter reading sequence (ReadPreference...)
Parameter reading sequence (ReadPreference...)
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.
-
- Enthusiast
- Posts: 581
- Joined: Wed Sep 25, 2019 10:18 am
Re: Parameter reading sequence (ReadPreference...)
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...)
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.
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.
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$)
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...)
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
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Parameter reading sequence (ReadPreference...)
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.
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.