Click here to Skip to main content
15,900,688 members
Home / Discussions / C#
   

C#

 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Richard Deeming30-Apr-24 0:12
mveRichard Deeming30-Apr-24 0:12 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Rob Philpott30-Apr-24 0:22
Rob Philpott30-Apr-24 0:22 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Jörgen Andersson30-Apr-24 2:15
professionalJörgen Andersson30-Apr-24 2:15 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Rob Philpott30-Apr-24 0:17
Rob Philpott30-Apr-24 0:17 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Jörgen Andersson30-Apr-24 3:14
professionalJörgen Andersson30-Apr-24 3:14 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Jörgen Andersson30-Apr-24 4:22
professionalJörgen Andersson30-Apr-24 4:22 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Rob Philpott30-Apr-24 4:27
Rob Philpott30-Apr-24 4:27 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
jschell30-Apr-24 12:17
jschell30-Apr-24 12:17 
Jörgen Andersson wrote:
It's strings.


For a dictionary then you are going to need to compute the hash.

Jörgen Andersson wrote:
And as the files


And then you must compute the hash for each of those.

I suspect this really depends on the size and probably the standard deviation of the sizes for each string.

I haven't thought this through and certainly have not profiled it but a tree might be better. The sparse tree is built with each fork having one character. Next level has 26 (or whatever size your set is) characters.

Keep in mind that a hash requires sequencing through each character. So a tree is somewhat similar to that EXCEPT when you reach the end (leaf of tree) you have already reached your delegate. So no further operations to look up.

If each level has the entire character set you can use an array and do a direct look up to the next level (the character is the index into the array.)

Carefully calculate the memory space. You could use a sparse tree but that will slow it down.

And maybe you should look at unmanaged code. Specifically C++.

One advantage to C++ (and C) is that you can force a string to be treated as a numeric. So a value like "ABCD" can be cast directly to a 32 bit unsigned integer. And of course you could use 64 bit also.

The problem with that of course is that you must then deal with 4/8 character size blocks only.

Jörgen Andersson wrote:
be worth some optimization.


You should actually profile the application. Not specific code but the entire application. If you want it to be fast then you should find the exact places where it is slow.
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Jörgen Andersson1-May-24 8:21
professionalJörgen Andersson1-May-24 8:21 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Jörgen Andersson1-May-24 8:49
professionalJörgen Andersson1-May-24 8:49 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Richard Deeming1-May-24 21:47
mveRichard Deeming1-May-24 21:47 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
trønderen2-May-24 6:50
trønderen2-May-24 6:50 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Richard Deeming2-May-24 21:39
mveRichard Deeming2-May-24 21:39 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Rob Philpott2-May-24 23:57
Rob Philpott2-May-24 23:57 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Richard Deeming3-May-24 0:39
mveRichard Deeming3-May-24 0:39 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
trønderen3-May-24 3:36
trønderen3-May-24 3:36 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
trønderen3-May-24 3:34
trønderen3-May-24 3:34 
Question3D графика Pin
Member 1381389024-Apr-24 19:16
professionalMember 1381389024-Apr-24 19:16 
GeneralRe: 3D графика Pin
Ralf Meier24-Apr-24 20:55
mveRalf Meier24-Apr-24 20:55 
AnswerRe: 3D графика Pin
Pete O'Hanlon24-Apr-24 20:58
mvePete O'Hanlon24-Apr-24 20:58 
GeneralRe: 3D графика Pin
Richard Deeming30-Apr-24 0:01
mveRichard Deeming30-Apr-24 0:01 
AnswerRe: 3D графика Pin
OriginalGriff24-Apr-24 21:47
mveOriginalGriff24-Apr-24 21:47 
QuestionHow to start creating a WinUI project ? Pin
Martin Adams 202324-Apr-24 2:54
Martin Adams 202324-Apr-24 2:54 
AnswerRe: How to start creating a WinUI project ? Pin
Richard MacCutchan24-Apr-24 3:45
mveRichard MacCutchan24-Apr-24 3:45 
GeneralRe: How to start creating a WinUI project ? Pin
Martin Adams 202324-Apr-24 6:02
Martin Adams 202324-Apr-24 6:02 

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.