> Why do you even need to bother optimising code at this level. After 4 years of learning my own bad habits by teaching myself, I have decided to attempt to become a more "efficient" developer. Where improvement is needed is still unclear at this point, but if I examine everything, surely I can only improve yes?? (Part of my motivation here is my recent move to .NET.. I understand I will need all the help I can get with that)
SaveToFile is only really used as a debugging tool in my isapi apps, or for my logs. I use mainly stringlists but never have a huge amount at one time. I am currently aware that string manipulation can be costly so it's a good place to start. Feel free to fire any good advice at me regarding "efficient" development =) And have a great day all =) Tracey -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dennis Chuah Sent: Wednesday, 11 August 2004 10:55 a.m. To: NZ Borland Developers Group - Delphi List Subject: Re: [DUG] Stringlist - to clear or not to clear 1. Try removing "SaveToFile" because that is an expensive operation and will cloud your results. 2. Why do you even need to bother optimising code at this level. Your example quite clearly shows there are better things to optimise (eg. your queries) than to worry about creating and freeing a couple of string lists. ----- Original Message ----- From: "tracey" <[EMAIL PROTECTED]> To: "NZ Borland Developers Group - Delphi List" <[EMAIL PROTECTED]> Sent: Wednesday, August 11, 2004 10:42 AM Subject: [DUG] Stringlist - to clear or not to clear > I would be interested to hear the opinion of all you gurus on the best > practice for re-using TStringLists. > > > > Scenario 1 > > > > Create > > Use > > Clear > > Re-use > > > > > > Scenario 2 > > Create > > Use > > Free > > > > Create > > Use > > Free > > > > I tried to test this myself by doing both ways and looping each 10000 times > but both take 11 seconds.. > > > > procedure TForm1.TestPerformance; > > var > > i: integer; > > testTimeStart, testTimeStop: TTime; > > begin > > > > testTimeStart := Now; > > for i := 0 to 10000 do > > begin > > sMessageBody := TStringList.Create; > > try > > sMessagebody.Add('This is a test to see which way is better.'); > > sMessageBody.Add(' This test is performed on the same > TStringList but freeing it then re-creating the stringlist'); > > sMessageBody.SaveToFile('test.txt'); > > finally > > sMessageBody.Free; > > end; > > > > end; > > testTimeStop := Now; > > ShowMessage('create then freee= ' + TimeToStr(testTimeStop - > testTimeStart)); > > > > testTimeStart := Now; > > try > > sMessageBody := TStringList.Create; > > for i := 0 to 10000 do > > begin > > sMessagebody.Add('This is a test to see which way is better.'); > > sMessageBody.Add(' This test is performed on the same > TStringList but clearing it then re-loading the strings'); > > sMessageBody.SaveToFile('test1.txt'); > > sMessageBody.Clear; > > end; > > finally > > sMessageBody.Free; > > testTimeStop := Now; > > ShowMessage('create once only= ' + TimeToStr(testTimeStop - > testTimeStart)); > > end; > > end; > > > > Which brings me to Q2 - How can I get a TTime to show ms? > > ---------------------------------------------------------------------------- ---- > _______________________________________________ > Delphi mailing list > [EMAIL PROTECTED] > http://ns3.123.co.nz/mailman/listinfo/delphi > _______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi _______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi
