Lavos Posted April 23, 2013 Author Share Posted April 23, 2013 Okay I have been studying many methods to create a string array for cache files and I've seen many methods, It blew my mind all week. I just need to know which method would be better in a system.Method Referenced by eclipse:```Public Tex_Floors() as stringPublic Count_Floor() as longCount_Floor = 1Do While FileExist(App.Path & PATH_FLOORS & Count_Floor & GFX_EXT, True)ReDim Preserve Tex_Floors(0 To Count_Floor) As StringTex_Floors(Count_Floor) = App.Path & PATH_FLOORS & Count_Floor & GFX_EXTCount_Floor = Count_Floor + 1LoopCount_Floor = Count_Floor - 1```V.S.Referenced by google researches```Public Tex_Floors(Floor_Count) as stringDim i as longFor i = 1 To UBound(Tex_Floors)Tex_Floors(i) = App.Path & PATH_FLOORS & i & GFX_EXTNext```Both blocks work fine, please be detailed on why you pick your answer, there is got to be a good reason in your theory or fact.Thank you. Link to comment Share on other sites More sharing options...
Stach Posted April 23, 2013 Share Posted April 23, 2013 The second block will execute faster:1. The size of the array is already set.2. It loops through and fills the array until it reaches the end of the array.The first block:1. Checks if the file exists first.2. If it does, it resizes the array then places the data inside.Although the performance isn't very significant (maybe a couple ms difference) the second block _is_ faster. The difference between the two is simply the Eclipse version doesn't know the size of the array so it sets it while loading it as in the second block already knows the size of the array. Link to comment Share on other sites More sharing options...
Lavos Posted April 23, 2013 Author Share Posted April 23, 2013 Your answer had me convinced, I think I may go with the second block. Thank you so much for telling me. I'll be following this topic for more answers in case if any one objects. Link to comment Share on other sites More sharing options...
Stach Posted April 23, 2013 Share Posted April 23, 2013 I did a benchmark. What I did was load an array 1,000,000 times using each method.Block One: 906msBlock Two: 125msYou can clearly see that the second method loads the data faster because you aren't re-sizing the array each time because it's already set. However, you're not loading 1,000,000 files so you would hardly see a difference anyway. Link to comment Share on other sites More sharing options...
Lavos Posted April 23, 2013 Author Share Posted April 23, 2013 How did you benchmark it? Doing whatever you did to get that result would help me a lot in the future for testing code. Link to comment Share on other sites More sharing options...
Stach Posted April 23, 2013 Share Posted April 23, 2013 Use GetTickCount. For example:```Dim tick As Long, tick2 As Longtick = GetTickCount `tick2 = GetTickCount` ``` `Then all you do is subtract tick2 from tick and that's how much time it took for the code in `to run.`` Link to comment Share on other sites More sharing options...
Lavos Posted April 23, 2013 Author Share Posted April 23, 2013 wow very simple! why didn't i think of that. thanks, i will try it with a msgbox. Link to comment Share on other sites More sharing options...
boyesjs03 Posted April 23, 2013 Share Posted April 23, 2013 > Use GetTickCount. For example:> > ```> > Dim tick As Long, tick2 As Long> > tick = GetTickCount> > `tick2 = GetTickCount` > ``` `Then all you do is subtract tick2 from tick and that's how much time it took for the code in `to run.`` ``Just thought I would say that is a pretty cool idea.`` 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