Click here to Skip to main content
15,923,789 members
Home / Discussions / C#
   

C#

 
GeneralRe: 'switch' statement efficiency in C# Pin
scody30-Jul-08 21:12
scody30-Jul-08 21:12 
AnswerRe: 'switch' statement efficiency in C# Pin
Guffa30-Jul-08 22:02
Guffa30-Jul-08 22:02 
GeneralRe: 'switch' statement efficiency in C# Pin
leppie30-Jul-08 22:52
leppie30-Jul-08 22:52 
GeneralRe: 'switch' statement efficiency in C# Pin
Christian Graus30-Jul-08 23:57
protectorChristian Graus30-Jul-08 23:57 
GeneralRe: 'switch' statement efficiency in C# Pin
leppie31-Jul-08 0:14
leppie31-Jul-08 0:14 
GeneralRe: 'switch' statement efficiency in C# Pin
Guffa31-Jul-08 1:57
Guffa31-Jul-08 1:57 
GeneralRe: 'switch' statement efficiency in C# Pin
leppie31-Jul-08 2:17
leppie31-Jul-08 2:17 
GeneralRe: 'switch' statement efficiency in C# Pin
Guffa31-Jul-08 2:58
Guffa31-Jul-08 2:58 
leppie wrote:
Eish, we are really splitting micro-bits here!


Yes, but it can at least be good to know that if you have a lot of case labels, you don't have to try to order them for performance.

leppie wrote:
What are you case labels for either case?


Just labels with strings and no code, so that it tests the performance of the switch only:
switch (selection) {
	case "00":
	case "01":
	case "02":
	case "03":
	case "04":
	case "05":
	default: break;
}

(I tested it with code in the cases also, so that I know that it behaves in the same manner.)

My results for a 10000000 loop for each case label, with switches having five and six case labels:
00 : 105 ms.
01 : 205 ms.
02 : 303 ms.
03 : 421 ms.
04 : 500 ms.

00 : 602 ms.
01 : 605 ms.
02 : 589 ms.
03 : 622 ms.
04 : 615 ms.
05 : 577 ms.

There is definitely a measurable performance difference for the first labels in the shorter switch, but even 60 ns. isn't much to whine about. Smile | :)

Despite everything, the person most likely to be fooling you next is yourself.

GeneralRe: 'switch' statement efficiency in C# Pin
leppie31-Jul-08 5:46
leppie31-Jul-08 5:46 
GeneralRe: 'switch' statement efficiency in C# Pin
leppie30-Jul-08 22:51
leppie30-Jul-08 22:51 
GeneralRe: 'switch' statement efficiency in C# Pin
Guffa31-Jul-08 1:18
Guffa31-Jul-08 1:18 
AnswerRe: 'switch' statement efficiency in C# Pin
PIEBALDconsult3-Aug-08 17:07
mvePIEBALDconsult3-Aug-08 17:07 
QuestionConvert a Java timestamp to C# DateTime object Pin
cyrus_virus30-Jul-08 19:26
cyrus_virus30-Jul-08 19:26 
AnswerRe: Convert a Java timestamp to C# DateTime object Pin
Christian Graus30-Jul-08 20:03
protectorChristian Graus30-Jul-08 20:03 
AnswerRe: Convert a Java timestamp to C# DateTime object Pin
Mike Dimmick31-Jul-08 1:16
Mike Dimmick31-Jul-08 1:16 
AnswerRe: Convert a Java timestamp to C# DateTime object Pin
curtisk31-Jul-08 3:49
curtisk31-Jul-08 3:49 
Questiongetting excel cell reference Pin
Mogaambo30-Jul-08 19:19
Mogaambo30-Jul-08 19:19 
Questionproblem to solve the warning!! Pin
ktamanna30-Jul-08 18:33
ktamanna30-Jul-08 18:33 
AnswerRe: problem to solve the warning!! Pin
Christian Graus30-Jul-08 19:39
protectorChristian Graus30-Jul-08 19:39 
AnswerRe: problem to solve the warning!! Pin
Vimalsoft(Pty) Ltd30-Jul-08 19:44
professionalVimalsoft(Pty) Ltd30-Jul-08 19:44 
Questionwhat type of value does switch statement allow to use?such as switch(?){....} Pin
panyl30-Jul-08 16:18
panyl30-Jul-08 16:18 
AnswerRe: what type of value does switch statement allow to use?such as switch(?){....} Pin
Christian Graus30-Jul-08 16:55
protectorChristian Graus30-Jul-08 16:55 
AnswerRe: what type of value does switch statement allow to use?such as switch(?){....} [modified] Pin
DaveyM6930-Jul-08 23:37
professionalDaveyM6930-Jul-08 23:37 
AnswerRe: what type of value does switch statement allow to use?such as switch(?){....} Pin
PIEBALDconsult3-Aug-08 17:01
mvePIEBALDconsult3-Aug-08 17:01 
QuestionHow to File Upload to Code project Pin
bruze30-Jul-08 11:31
bruze30-Jul-08 11:31 

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.