Click here to Skip to main content
15,895,667 members
Home / Discussions / C#
   

C#

 
AnswerRe: Right tool for the job Pin
J4amieC6-Sep-07 2:54
J4amieC6-Sep-07 2:54 
GeneralRe: Right tool for the job Pin
Senseicads6-Sep-07 3:01
Senseicads6-Sep-07 3:01 
GeneralRe: Right tool for the job Pin
Christian Graus6-Sep-07 3:10
protectorChristian Graus6-Sep-07 3:10 
AnswerRe: Right tool for the job Pin
Rick van Woudenberg6-Sep-07 9:17
Rick van Woudenberg6-Sep-07 9:17 
QuestionHashtable vs Dictionary. Pin
nasambur6-Sep-07 2:06
nasambur6-Sep-07 2:06 
AnswerRe: Hashtable vs Dictionary. Pin
Sandeep Akhare6-Sep-07 2:12
Sandeep Akhare6-Sep-07 2:12 
AnswerRe: Hashtable vs Dictionary. Pin
Pete O'Hanlon6-Sep-07 2:49
mvePete O'Hanlon6-Sep-07 2:49 
AnswerRe: Hashtable vs Dictionary. Pin
Matthew Cuba6-Sep-07 4:47
Matthew Cuba6-Sep-07 4:47 
Maybe 50 lines (or less!) would provide you with insertion/retrieval times for both.

Just for fun, I used the System.Diagnostics.Stopwatch class to get the elapsed time on adding 10,000,000 ints to both a HashTable and a Dictionary<int,int> and found that the Dictionary was faster both for insertion and retrieval.

I just for-looped for the desired number of iterations and added the counter each time to the container. On the retrieval, I just did a [key] lookup and an assigment, something like:

myint = container[key];

On the hashtable part, I did a Convert.To.Int32() call. On the Dictionary, it *knew* it was an Int already, so I just did the assignment. So, that Convert call took some time. I went back and took out the Convert call to see what impact that was having - not much, actually. Maybe 100-150 milliseconds on average for the entire run.

Interestingly (at least to me), the Hashtable was slower on retrieval when I specified the initial capacity at construction than when I didn't. For 10,000,000 items, it took about 700 milliseconds or so longer for the entire run.

Of course, your mileage may vary and my test program was not an exhaustive one.

That was as fun diversion - back to work I go!

Have fun,
Matt

It isn't enough to do well in life.
One must do good when and where one can.
Otherwise, what's the point?

GeneralRe: Hashtable vs Dictionary. Pin
Jason Hanford-Smith6-Sep-07 7:13
Jason Hanford-Smith6-Sep-07 7:13 
GeneralRe: Hashtable vs Dictionary. Pin
Matthew Cuba6-Sep-07 7:32
Matthew Cuba6-Sep-07 7:32 
GeneralRe: Hashtable vs Dictionary. Pin
Jason Hanford-Smith6-Sep-07 7:43
Jason Hanford-Smith6-Sep-07 7:43 
GeneralRe: Hashtable vs Dictionary. Pin
Matthew Cuba6-Sep-07 7:53
Matthew Cuba6-Sep-07 7:53 
GeneralRe: Hashtable vs Dictionary. Pin
Jason Hanford-Smith6-Sep-07 9:12
Jason Hanford-Smith6-Sep-07 9:12 
GeneralRe: Hashtable vs Dictionary. Pin
Matthew Cuba6-Sep-07 9:18
Matthew Cuba6-Sep-07 9:18 
QuestionFlickering PictureBoxes in C# Pin
Ermak866-Sep-07 1:59
Ermak866-Sep-07 1:59 
AnswerRe: Flickering PictureBoxes in C# Pin
Christian Graus6-Sep-07 2:11
protectorChristian Graus6-Sep-07 2:11 
GeneralRe: Flickering PictureBoxes in C# Pin
Ermak866-Sep-07 2:14
Ermak866-Sep-07 2:14 
GeneralRe: Flickering PictureBoxes in C# Pin
Christian Graus6-Sep-07 2:39
protectorChristian Graus6-Sep-07 2:39 
QuestionCash for Help! Pin
MicealG6-Sep-07 1:42
MicealG6-Sep-07 1:42 
JokeRe: Cash for Help! Pin
Sandeep Akhare6-Sep-07 1:46
Sandeep Akhare6-Sep-07 1:46 
GeneralRe: Cash for Help! Pin
MicealG6-Sep-07 1:50
MicealG6-Sep-07 1:50 
GeneralRe: Cash for Help! [modified] Pin
Sandeep Akhare6-Sep-07 2:00
Sandeep Akhare6-Sep-07 2:00 
GeneralRe: Cash for Help! Pin
MicealG6-Sep-07 3:37
MicealG6-Sep-07 3:37 
AnswerRe: Cash for Help! Pin
Ravi Bhavnani6-Sep-07 1:54
professionalRavi Bhavnani6-Sep-07 1:54 
GeneralStill No Answer Pin
MicealG6-Sep-07 2:01
MicealG6-Sep-07 2:01 

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.