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