Click here to Skip to main content
16,006,341 members
Home / Discussions / C#
   

C#

 
GeneralRe: project problem Pin
dan_ta2227-Jun-04 14:24
dan_ta2227-Jun-04 14:24 
GeneralRe: project problem Pin
LongRange.Shooter24-Jun-04 8:52
LongRange.Shooter24-Jun-04 8:52 
GeneralRe: project problem Pin
dan_ta2227-Jun-04 14:29
dan_ta2227-Jun-04 14:29 
GeneralA windows service with System.Web.Mail Pin
Valdair23-Jun-04 15:09
Valdair23-Jun-04 15:09 
GeneralRe: A windows service with System.Web.Mail Pin
eggie523-Jun-04 16:05
eggie523-Jun-04 16:05 
GeneralRe: A windows service with System.Web.Mail Pin
Valdair24-Jun-04 7:04
Valdair24-Jun-04 7:04 
GeneralRe: A windows service with System.Web.Mail Pin
Heath Stewart24-Jun-04 12:44
protectorHeath Stewart24-Jun-04 12:44 
GeneralSurprising performance difference Pin
the real bryon23-Jun-04 12:09
the real bryon23-Jun-04 12:09 
Hello,

I recently stumbled across a huge performance difference involving writing out a large hash table to a file. The hashtable is holding a very simple object called Token, that holds a string value called token and a couple counters. ToString() is overriden for the object to return:

tokenstring [space] counter1 [space] counter2

If I iterate through the values of the hashtable and write it out to a file, it takes around 1 minute and 40 seconds to complete.

Seems a little slow. Here is the weird part. If I iterate through the values of the hashtable and add them to an arraylist and then iterate through the arraylist to write out the values, it takes between 10 and 12 seconds.

The hash table is large, as the file that is written out is 39 Mb where each line is around 18 characters, where each line represents one hash table entry.

Below is some of my test code to clarify the situation if my explanation above has anyone confused. WriteTokensSlow takes about 1 minutes and 40 seconds. WriteTokensFast takes between 10 and 12 seconds.

private void WriteTokensSlow()
{
WriteCollection(tokensHT.Values);
}

private void WriteTokensFast()
{
ArrayList tokenList = new ArrayList(tokensHT.Values);
WriteCollection(tokenList);
}

private void WriteCollection(ICollection collection)
{
using (StreamWriter sw = new StreamWriter(savePath,false))
{
foreach (Token tokenItem in collection)
sw.WriteLine(tokenItem.ToString());
}
}


Can anyone explain why this is happening? Thanks.
GeneralRe: Surprising performance difference Pin
leppie23-Jun-04 13:02
leppie23-Jun-04 13:02 
GeneralRe: Surprising performance difference Pin
Heath Stewart24-Jun-04 5:00
protectorHeath Stewart24-Jun-04 5:00 
GeneralRe: Surprising performance difference Pin
Jeremy Kimball24-Jun-04 6:07
Jeremy Kimball24-Jun-04 6:07 
GeneralRe: Surprising performance difference Pin
Heath Stewart24-Jun-04 6:50
protectorHeath Stewart24-Jun-04 6:50 
GeneralRe: Surprising performance difference Pin
Jeremy Kimball25-Jun-04 1:39
Jeremy Kimball25-Jun-04 1:39 
GeneralRe: Surprising performance difference Pin
Heath Stewart25-Jun-04 3:35
protectorHeath Stewart25-Jun-04 3:35 
GeneralRe: Surprising performance difference Pin
the real bryon24-Jun-04 6:59
the real bryon24-Jun-04 6:59 
GeneralRe: Surprising performance difference Pin
Heath Stewart24-Jun-04 9:04
protectorHeath Stewart24-Jun-04 9:04 
GeneralRe: Surprising performance difference Pin
the real bryon24-Jun-04 12:09
the real bryon24-Jun-04 12:09 
GeneralRe: Surprising performance difference Pin
Heath Stewart24-Jun-04 12:34
protectorHeath Stewart24-Jun-04 12:34 
GeneralRe: Surprising performance difference Pin
leppie24-Jun-04 7:16
leppie24-Jun-04 7:16 
GeneralRe: Surprising performance difference Pin
Heath Stewart24-Jun-04 8:51
protectorHeath Stewart24-Jun-04 8:51 
GeneralDbNull to integer Pin
IamADotNetGuy23-Jun-04 10:54
IamADotNetGuy23-Jun-04 10:54 
GeneralRe: DbNull to integer Pin
Colin Angus Mackay23-Jun-04 11:00
Colin Angus Mackay23-Jun-04 11:00 
GeneralRe: DbNull to integer Pin
IamADotNetGuy23-Jun-04 11:03
IamADotNetGuy23-Jun-04 11:03 
GeneralRe: DbNull to integer Pin
Colin Angus Mackay23-Jun-04 11:10
Colin Angus Mackay23-Jun-04 11:10 
GeneralRe: DbNull to integer Pin
Valdair24-Jun-04 7:19
Valdair24-Jun-04 7:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.