Title: Message
Woops. Forget about my Timer comment. I saw TTime and read TTimer.
 
Stacey
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Stacey Verner
Sent: Wednesday, 11 August 2004 10:47
To: NZ Borland Developers Group - Delphi List
Subject: RE: [DUG] Stringlist - to clear or not to clear

There won't be any performance difference as both options are essentially the same. Free does a clear first anyway and the time taken to destroy and create the objects is minimal.
 
Conventinal wisdom says that you should avoid reusing variables for different tasks to avoid confusion.
 
You don't need to use a timer to see how long something takes. Timers are for repeating.
 
Instead do something like:
 
LStart := Now;
 
// Do your stuff.
 
ShowMessage(FormatDateTime('ss', Now - LStart));
 
Stacey
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of tracey
Sent: Wednesday, 11 August 2004 10:43
To: NZ Borland Developers Group - Delphi List
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 + 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

Reply via email to