hannes08 Posted February 10, 2011 Share Posted February 10, 2011 Hi guys, I need to read a lot of sections from a INI file to do some monitoring. So I used IniReadSection to get a 2-dim array for each section. Now my thought is, If I have all the contents from that INI in an array there is no need to read the file from the HDD every time, I'm going to write a small function to replace IniReadSection(). Here is the code: Func _NewInireadSec(ByRef $array, $name) Local $i, $j Dim $ret[1][2] $ret[0][0] = 0 $i = _ArraySearch($array, "[" & $name & "]") If $i > 0 Then For $j = $i + 1 To UBound($array) - 1 If StringLeft(StringStripWS($array[$j],1),1) = "[" And StringRight(StringStripWS($array[$j],2),1) = "]" Then Return SetError(0, 0, $ret) $ret[0][0] += 1 ReDim $ret[$ret[0][0] + 1][2] $i_eq_pos = StringInStr($array[$j],"=") $ret[$ret[0][0]][0] = StringMid($array[$j],1,$i_eq_pos - 1) $ret[$ret[0][0]][1] = StringMid($array[$j],$i_eq_pos + 1) Next EndIf Return SetError(1, @error, -1) EndFunc Now what makes me wonder: this function is about 15 times slower that IniReadSection! I know the AutoIt guys are really really good in what they do. But 15 times slower? Any clues to speed up the function? Regards, Hannes Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
GEOSoft Posted February 10, 2011 Share Posted February 10, 2011 Sure, write it properly in C++ and you will end up at about 10 times slower than IniReadSection(). You will NEVER make that method run nearly as fast as IniReadSection() for several reasons. Look at how many calls you are making to other functions (which have to be interpreted) and on top of that you are using a very slow function with ReDim and you are running it through a loop which will automaticlly induce a (very) tiny delay with each iteration. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
hannes08 Posted February 10, 2011 Author Share Posted February 10, 2011 Hi GEOSoft, I was pretty sure myself that this will NEVER be as fast as IniReadSection when I saw the result. I was just curios about the reason why. Now with that explanation we could mark this topic as solved. Thanks, anyway! Hannes Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
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