Sounds like you dont really need sorting.
You could for instance create a class that holds the IP address, count, and
bytes. Now maintain a list of these classes. Read through the file once, and
for each line extract the IP address and bytes. If the IP address is in your
list, increment the count and add the bytes. If not, add a new object to the
list, setting the count to 1. This minimises your I/O and avoids sorting
BUT:
- if you have a high number of unique IP addresses, the performance will be
no better (and perhaps worse) than using a sort.
Of course, if it is only one IP address that you are interested in, you can
ignore all the other IP addresses.
Hope this helps,
Andrew Cooke.
> -----Original Message-----
> From: Jeremy Coulter [SMTP:[EMAIL PROTECTED]]
> Sent: Wednesday, November 17, 1999 8:29 AM
> To: Multiple recipients of list delphi
> Subject: [DUG]: Sorting
>
> Hi all.
>
> I have been working on a wee logfile analyzer component for myself.
> Basically it loads a CSV file(like one generated bt IIS) into memory and
> then analyzes the entries.
> I.e. in the case of the CSV file from IIS which i am using for developing,
> it calculates how many times an IP adress appears, and calculates how many
> bytes were sent to that IP address, i.e. the result :=
> 192.168.0.1,20,10000
> (ip address, number of times it appears, how man bytes)
>
> Anyway, one of the things I do is load the file into a TStringList, and
> then
> I sort it so i get all the, in this case, IP address grouped togeither,
> which makes it easier to calculate everything, as all the relevient data
> is
> all togeiter.
>
> BUT, I have a 7322 line file, and if I sort it, the process of zipping
> through the file takes 22 seconds, remove the sorting, 0.461 seconds !!!!
>
> SO, is there a faster way of sorting ?
> Should I use an inmemory table...and if so, can I sort the fields etc.....
>
> Any suggestions,
>
> Cheers, Jeremy Coulter
>
>
> --------------------------------------------------------------------------
> -
> New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz