jondolar Posted September 8, 2005 Posted September 8, 2005 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
/dev/null Posted September 8, 2005 Posted September 8, 2005 (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?? CheersKurt Edited September 8, 2005 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 *
jondolar Posted September 8, 2005 Author Posted September 8, 2005 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?? CheersKurt<{POST_SNAPBACK}>Hi KurtPoor's man database ;o) Not adequeate I guess.
jondolar Posted September 9, 2005 Author Posted September 9, 2005 Hi KurtPoor's man database ;o) Not adequeate I guess.<{POST_SNAPBACK}>HiI 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 EndIfInteresting Serge
falconv Posted September 9, 2005 Posted September 9, 2005 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?
jondolar Posted September 9, 2005 Author Posted September 9, 2005 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)RegardsSerge
erifash Posted September 10, 2005 Posted September 10, 2005 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 My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver
Gigglestick Posted September 10, 2005 Posted September 10, 2005 (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 September 10, 2005 by c0deWorm My UDFs: ExitCodes
jondolar Posted September 10, 2005 Author Posted September 10, 2005 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}>Meta tags?... be interested to have info on that.Serge
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now