Sign in to follow this  
Followers 0
jondolar

Ini file VS Text File

9 posts in this topic

I'm new to Autoit3 and experimenting.

I wanted to compare the Write speed of both an Ini file and a plain text file

the result for an ini file with 1,000 elements is 15 sec with the following code:

$i = 0
While $i <= 1000
      IniWrite("D:\Autoit3\Serge\MYINI.ini", $i, $i, $i)
      $i = $i + 1
Wend

To write 100,000 elements to a plain text file took only a few seconds with:

$i = 0
$handle =  FileOpen("D:\autoit3\Serge\Sergetxt.txt", 1 )
while $i <= 100000
        FileWriteLine($handle, $i & " The quick Brown Fox Jumped over the fence")
        $i = $i + 1
wend
FileClose($handle)

Any Idea why writing to an ini file is so slow?

Regards

Serge

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Any Idea why writing to an ini file is so slow?

well, IniWrite uses the windows API function WritePrivateProfileString.

Short story: I guess we'll have to ask Microsoft here ;)

Longer story: To write a single line to a file is pretty fast. Writing to an ini file, requires to parse that file and figure out if the requested section is part of the file, etc., etc. AND adding some text in the middle of the INI file will allways end up in reading the whole file, changing things in memory and writing the whole "new" content back to disk.

Just curious: Why would you want to write massive data into an INI file??

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

well, IniWrite uses the windows API function WritePrivateProfileString.

Short story: I guess we'll  have to ask Microsoft here  ;)

Longer story: To write a single line to a file is pretty fast. Writing to an ini file, requires to parse that file and figure out if the requested section is part of the file, etc., etc. AND adding some text in the middle of the INI file will allways end up in reading the whole file, changing things in memory and writing the whole "new" content back to disk.

Just curious: Why would you want to write massive data into an INI file??

Cheers

Kurt

<{POST_SNAPBACK}>

Hi Kurt

Poor's man database ;o) Not adequeate I guess.

Share this post


Link to post
Share on other sites

Hi Kurt

Poor's man database ;o) Not adequeate I guess.

<{POST_SNAPBACK}>

Hi

I actually made an interesting small discovery.

Using FileWriteLine to simulate an INI file like this:

$i = 0
$handle =  FileOpen("D:\autoit3\Serge\SergeINI.txt", 1 ); Write a simulated INI file
while $i <= 10000
        FileWriteLine($handle, "[" & $i & "]")
        FileWriteLine($handle, $i & "=" & $i)
        $i = $i + 1
wend
FileClose($handle)

You write at hi speed txt file and can still use IniReadSection for example:

$i = 0
$var = IniReadSection("D:\Autoit3\Serge\SergeINI.txt", "4"); Read ini/txt file
If @error Then  
    MsgBox(4096, "", "Error occured, probably no INI file.")
Else
    For $i = 1 To $var[0][0]
        MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])
    Next
EndIf

Interesting

Serge

Share this post


Link to post
Share on other sites

That *is* a neat discovery. I'll keep that in mind when creating new db's wi/ .ini files. However, that will only work efficiently if you're writing the data new. If you want to change the data in the .ini file, that's a different story. Although perhaps if someone wanted to spend the time (I don't, I'm happy with IniWrite) I suppose you could make a Function to simulate it, so it will search the file for the entry and replace it?

Share this post


Link to post
Share on other sites

That *is* a neat discovery.  I'll keep that in mind when creating new db's wi/ .ini files.  However, that will only work efficiently if you're writing the data new.  If you want to change the data in the .ini file, that's a different story.  Although perhaps if someone wanted to spend the time (I don't, I'm happy with IniWrite) I suppose you could make a Function to simulate it, so it will search the file for the entry and replace it?

<{POST_SNAPBACK}>

Since Writing/Reading to/from a text file is so fast, I suppose you could read the entire file to an array, do your search/replace there then write the entire pseudo ini file back to disk and still use IniReadSection to fetch a specific "Record" and IniDelete to delete a specific "record". For a veryvery small file, pure ini is ok but when you go past 100 entries, it is extremely slow (1000 entries = 15 sec)

Regards

Serge

Share this post


Link to post
Share on other sites

That *is* a neat discovery.  I'll keep that in mind when creating new db's wi/ .ini files.  However, that will only work efficiently if you're writing the data new.  If you want to change the data in the .ini file, that's a different story.  Although perhaps if someone wanted to spend the time (I don't, I'm happy with IniWrite) I suppose you could make a Function to simulate it, so it will search the file for the entry and replace it?

<{POST_SNAPBACK}>

Yup, I made something almost exactly like that a while ago. I abandoned it for storing information in meta tags (easier to parse). Here's the link:

http://www.autoitscript.com/forum/index.php?showtopic=14157

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Yup, I made something almost exactly like that a while ago. I abandoned it for storing information in meta tags (easier to parse). Here's the link:

http://www.autoitscript.com/forum/index.php?showtopic=14157

<{POST_SNAPBACK}>

I don't know about you, jondolar, but that's exactly what I was looking for! ;)

http://www.autoitscript.com/fileman/users/public/c0deWorm/Three_Chipmonks.gif

Edited by c0deWorm

My UDFs: ExitCodes

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0