Jump to content
Sign in to follow this  
dimon

CAll vs SWITCH

Recommended Posts

I quote from the article Code Optimisation:

If Else If Else If Else ...

If you can't escape this using a switch control structure, then try and rethink the functionality. Especially if only one option is needed to match.

On the other hand switch is slower than if then else. To keep tidiness of the switch and speed of if, use if exitWith combined with call:

call {
if (cond1) exitWith {//code 1};
if (cond2) exitWith {//code 2};
if (cond3) exitWith {//code 3};
//default code
};

All right...

	private '_condition';
_condition=10;
switch (true) do
{
	case (_condition == 1):{};
	case (_condition == 2):{};
	case (_condition == 3):{};
	case (_condition == 4):{};
	case (_condition == 5):{};
	case (_condition == 6):{};
	case (_condition == 7):{};
	case (_condition == 8):{};
	case (_condition == 9):{};
	case (_condition == 10):{};
};

59e76eb539cfa311a518df8a8fba7ea4.jpeg

... will be slower than

	private '_condition';
_condition=10;
call {
	if (_condition==1) exitwith {};
	if (_condition==2) exitwith {};
	if (_condition==3) exitwith {};
	if (_condition==4) exitwith {};
	if (_condition==5) exitwith {};
	if (_condition==6) exitwith {};
	if (_condition==7) exitwith {};
	if (_condition==8) exitwith {};
	if (_condition==9) exitwith {};
	if (_condition==10) exitwith {};
};

96fc98fc01a5db830ea4179add6e0669.jpeg

But not everything is so simple....

	private '_condition';
_condition=10;
 switch (_condition) do
{
	case 1:{};
	case 2:{};
	case 3:{};
	case 4:{};
	case 5:{};
	case 6:{};
	case 7:{};
	case 8:{};
	case 9:{};
	case 10:{};
};

57a5fa9c07b971dda0c4b11114f17b98.jpeg

Share this post


Link to post
Share on other sites

In order to compare something you have to have same or similar conditions, like in first 2 examples, 3rd example is different because it does not even check for booleans.

Share this post


Link to post
Share on other sites
In order to compare something you have to have same or similar conditions, like in first 2 examples, 3rd example is different because it does not even check for booleans.

But they solve one problem?

Ðо они же решают одну задачу?

Share this post


Link to post
Share on other sites

In general, such "code optimization" is bullshit. Use whatever is *more readable*, or feels better to you. Then stick to it.

I, for one, like the switch(true)-thingy very much. :D

I highly doubt you could measure a significant difference in "performance" (with a resolution of 1ms anyways...). And even if, unless you're doing such a switch a gazillion times inside a loop or something, you really do not need to worry about such things. It will be fine.

P.S. diag_tickTime exists. Go ahead, have fun ;)

Share this post


Link to post
Share on other sites
But they solve one problem?

Ðо они же решают одну задачу?

Sorry but if you want to compare command vs command without knowing task at hand, you create similar conditions, if you want to optimise a particular problem solving then you do just that:

[color="#FF8040"][color="#191970"][b]private[/b][/color] [color="#7A7A7A"]'_condition'[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_condition[/color][color="#8B3E2F"][b]=[/b][/color][color="#FF0000"]10[/color][color="#8B3E2F"][b];[/b][/color]	
[color="#191970"][b]call[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b][[/b][/color]
[color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color]
[color="#8B3E2F"][b]][/b][/color] [color="#191970"][b]select[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]-[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

Made with KK's SQF to BBCode Converter

---------- Post added at 15:26 ---------- Previous post was at 15:18 ----------

In general, such "code optimization" is bullshit.

In general "code optimization" does not mean "optimised for reading"

Share this post


Link to post
Share on other sites

Yes, but the case could be so:

[color="#FF8040"] [color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"zzzzzzzzzzzz"[/color][color="#8B3E2F"][b];[/b][/color]
      [color="#191970"][b]switch[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]do[/b][/color]
       [color="#8B3E2F"][b]{[/b][/color]
            [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"aaaaaaaaaaaa"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"bbbbbbbbbbbb"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"cccccccccccc"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"dddddddddddd"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"eeeeeeeeeeee"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"ffffffffffff"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"gggggggggggg"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"hhhhhhhhhhhh"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"iiiiiiiiiiii"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"jjjjjjjjjjjj"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"kkkkkkkkkkkk"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"llllllllllll"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"mmmmmmmmmmmm"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"nnnnnnnnnnnn"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"oooooooooooo"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"pppppppppppp"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"qqqqqqqqqqqq"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"rrrrrrrrrrrr"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"ssssssssssss"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"tttttttttttt"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"uuuuuuuuuuuu"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"vvvvvvvvvvvv"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"wwwwwwwwwwww"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"xxxxxxxxxxxx"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"yyyyyyyyyyyy"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"zzzzzzzzzzzz"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
       [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

[color="#FF8040"]   [color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"zzzzzzzzzzzz"[/color][color="#8B3E2F"][b];[/b][/color]
       [color="#191970"][b]call[/b][/color]
       [color="#8B3E2F"][b]{[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"aaaaaaaaaaaa"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"bbbbbbbbbbbb"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"cccccccccccc"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"dddddddddddd"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"eeeeeeeeeeee"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"ffffffffffff"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"gggggggggggg"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"hhhhhhhhhhhh"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"iiiiiiiiiiii"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"jjjjjjjjjjjj"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"kkkkkkkkkkkk"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"llllllllllll"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"mmmmmmmmmmmm"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"nnnnnnnnnnnn"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"oooooooooooo"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"pppppppppppp"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"qqqqqqqqqqqq"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"rrrrrrrrrrrr"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"ssssssssssss"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"tttttttttttt"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"uuuuuuuuuuuu"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"vvvvvvvvvvvv"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"wwwwwwwwwwww"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"xxxxxxxxxxxx"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"yyyyyyyyyyyy"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"zzzzzzzzzzzz"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
       [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

Share this post


Link to post
Share on other sites
In general, such "code optimization" is bullshit. Use whatever is *more readable*, or feels better to you. Then stick to it.

I, for one, like the switch(true)-thingy very much. :D

I highly doubt you could measure a significant difference in "performance" (with a resolution of 1ms anyways...). And even if, unless you're doing such a switch a gazillion times inside a loop or something, you really do not need to worry about such things. It will be fine.

P.S. diag_tickTime exists. Go ahead, have fun ;)

Have to agree with your first line, to an extent. Reminds me of the health supplements industry. Might make 2-3% improvement over the long run, but cost a fortune, in our case, time instead of money.

Share this post


Link to post
Share on other sites
Yes, but the case could be so:

[color="#FF8040"] [color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"zzzzzzzzzzzz"[/color][color="#8B3E2F"][b];[/b][/color]
      [color="#191970"][b]switch[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]do[/b][/color]
       [color="#8B3E2F"][b]{[/b][/color]
            [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"aaaaaaaaaaaa"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"bbbbbbbbbbbb"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"cccccccccccc"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"dddddddddddd"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"eeeeeeeeeeee"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"ffffffffffff"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"gggggggggggg"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"hhhhhhhhhhhh"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"iiiiiiiiiiii"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"jjjjjjjjjjjj"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"kkkkkkkkkkkk"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"llllllllllll"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"mmmmmmmmmmmm"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"nnnnnnnnnnnn"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"oooooooooooo"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"pppppppppppp"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"qqqqqqqqqqqq"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"rrrrrrrrrrrr"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"ssssssssssss"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"tttttttttttt"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"uuuuuuuuuuuu"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"vvvvvvvvvvvv"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"wwwwwwwwwwww"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"xxxxxxxxxxxx"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"yyyyyyyyyyyy"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]case[/b][/color] [color="#7A7A7A"]"zzzzzzzzzzzz"[/color][color="#8B3E2F"][b]:[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
       [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

[color="#FF8040"]   [color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"zzzzzzzzzzzz"[/color][color="#8B3E2F"][b];[/b][/color]
       [color="#191970"][b]call[/b][/color]
       [color="#8B3E2F"][b]{[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"aaaaaaaaaaaa"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"bbbbbbbbbbbb"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"cccccccccccc"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"dddddddddddd"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"eeeeeeeeeeee"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"ffffffffffff"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"gggggggggggg"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"hhhhhhhhhhhh"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"iiiiiiiiiiii"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"jjjjjjjjjjjj"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"kkkkkkkkkkkk"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"llllllllllll"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"mmmmmmmmmmmm"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"nnnnnnnnnnnn"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"oooooooooooo"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"pppppppppppp"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"qqqqqqqqqqqq"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"rrrrrrrrrrrr"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"ssssssssssss"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"tttttttttttt"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"uuuuuuuuuuuu"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"vvvvvvvvvvvv"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"wwwwwwwwwwww"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"xxxxxxxxxxxx"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"yyyyyyyyyyyy"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
           [color="#191970"][b]if[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"zzzzzzzzzzzz"[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]exitWith[/b][/color]
           [color="#8B3E2F"][b]{[/b][/color]

           [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
       [color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

Again, you seem to fail to grasp the idea of comparison of different commands, you have to put commands in similar conditions. The equivalent construct in this case would be

[color="#FF8040"][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"zzzzzzzzzzzz"[/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]switch[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#000000"]true[/color][color="#8B3E2F"][b])[/b][/color] [color="#191970"][b]do[/b][/color]
[color="#8B3E2F"][b]{[/b][/color]
[color="#191970"][b]case[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color][color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"aaaaaaaaaaaa"[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b]:[/b][/color]
[color="#8B3E2F"][b]{[/b][/color]

[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color]
.......
[color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

Made with KK's SQF to BBCode Converter

However switch is still slower than:

[color="#FF8040"][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"zzzzzzzzzzzz"[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_arr[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color]
[color="#7A7A7A"]"aaaaaaaaaaaa"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"bbbbbbbbbbbb"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"cccccccccccc"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"dddddddddddd"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"eeeeeeeeeeee"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"ffffffffffff"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"gggggggggggg"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"hhhhhhhhhhhh"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"iiiiiiiiiiii"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"jjjjjjjjjjjj"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"kkkkkkkkkkkk"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"llllllllllll"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"mmmmmmmmmmmm"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"nnnnnnnnnnnn"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"oooooooooooo"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"pppppppppppp"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"qqqqqqqqqqqq"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"rrrrrrrrrrrr"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"ssssssssssss"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"tttttttttttt"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"uuuuuuuuuuuu"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"vvvvvvvvvvvv"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"wwwwwwwwwwww"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"xxxxxxxxxxxx"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"yyyyyyyyyyyy"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"zzzzzzzzzzzz"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color]
[color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]call[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_arr[/color] [color="#191970"][b]select[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_arr[/color] [color="#191970"][b]find[/b][/color] [color="#1874CD"]_condition[/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]+[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

Made with KK's SQF to BBCode Converter

Share this post


Link to post
Share on other sites
In general "code optimization" does not mean "optimised for reading"

That's not what I've ment. Nice, readable code is more important (in the long run anyways, and hey; it's ArmA we're talking about!) than a "faster" switch. Because that switch is most likely fast enough already/not a bottleneck. And if you're going to rewrite that switch-statement, maybe do some measurings first to see where your work is needed most. Otherwise you're just wasting your time.

Sure, if you're going to call that switch each frame, maybe multiple times even, we can talk about it (again, maybe try to measure it), ;). Otherwise, or in general, I wouldn't suggest to write such a call thingy that relies on find/linear search (natively implemented) just to gain a bunch of microseconds (or what?). Plus it's a lot less general, than a switch(true)-statement, where you can put any conditions/expressions you like. Find doesn't exactly work like that (granted, that call/exitWith-construct isn't too bad).

Plus: your example really looks like you want to use a hash-table/a dictionary/err... an assoc. array :wave: as a datastructure anyways. So there is no need to compare this to a switch statement. And then, maybe use a proper hash/dictionary ds, right. Then you're back(?) up to speed, and it will read nicely too! :)

Btw., I've just seen that you've got a really nice blog going over there. Keep it up! You're showing some really nice things (that uav-pip-laptop is amazing! :yay:).

Bookmarked right away!

Edited by ruebe

Share this post


Link to post
Share on other sites

While entering the game, with more than 200 online players, the server plenty of time become microseconds to seconds. And any important optimization: how to approach writing and reading speed of the code.

---------- Post added at 07:12 ---------- Previous post was at 07:04 ----------

Again, you seem to fail to grasp the idea of comparison of different commands, you have to put commands in similar conditions. The equivalent construct in this case would be

However switch is still slower than:

[color="#FF8040"][color="#1874CD"]_condition[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#7A7A7A"]"zzzzzzzzzzzz"[/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_arr[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color]
[color="#7A7A7A"]"aaaaaaaaaaaa"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"bbbbbbbbbbbb"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"cccccccccccc"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"dddddddddddd"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"eeeeeeeeeeee"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"ffffffffffff"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"gggggggggggg"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"hhhhhhhhhhhh"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"iiiiiiiiiiii"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"jjjjjjjjjjjj"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"kkkkkkkkkkkk"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"llllllllllll"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"mmmmmmmmmmmm"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"nnnnnnnnnnnn"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"oooooooooooo"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"pppppppppppp"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"qqqqqqqqqqqq"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"rrrrrrrrrrrr"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"ssssssssssss"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"tttttttttttt"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"uuuuuuuuuuuu"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"vvvvvvvvvvvv"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"wwwwwwwwwwww"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"xxxxxxxxxxxx"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"yyyyyyyyyyyy"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color][color="#8B3E2F"][b],[/b][/color]
[color="#7A7A7A"]"zzzzzzzzzzzz"[/color][color="#8B3E2F"][b],[/b][/color][color="#8B3E2F"][b]{[/b][/color][color="#8B3E2F"][b]}[/b][/color]
[color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#191970"][b]call[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_arr[/color] [color="#191970"][b]select[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#8B3E2F"][b]([/b][/color][color="#1874CD"]_arr[/color] [color="#191970"][b]find[/b][/color] [color="#1874CD"]_condition[/color][color="#8B3E2F"][b])[/b][/color] [color="#8B3E2F"][b]+[/b][/color] [color="#FF0000"]1[/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

Made with KK's SQF to BBCode Converter

Thank you. Always learn something from you new.

Ох, Ñтот гугл переводчик... Вообщем Ñ Ð´ÑƒÐ¼Ð°ÑŽ что при одновременном входе в игру 200 игроков, или Ñ Ð¾Ð½Ð»Ð°Ð¹Ð½Ð¾Ð¼ более 200 игроков важна Ð»ÑŽÐ±Ð°Ñ Ð¾Ð¿Ñ‚Ð¸Ð¼Ð¸Ð·Ð°Ñ†Ð¸Ñ : как и в подходе напиÑÐ°Ð½Ð¸Ñ ÐºÐ¾Ð´Ð°, так и в Ñамом напиÑании - то еÑÑ‚ÑŒ поиÑк Ñамого быÑтрого ÑчитываниÑ. Ибо миллиÑекунды ÑтановÑÑ‚ÑÑ Ñекундами. Killzone_Kid, ÑпаÑибо за примеры - вÑегда от Ð²Ð°Ñ ÑƒÐ·Ð½Ð°ÑŽ чего-то нового Ð´Ð»Ñ ÑебÑ.

Edited by Dimon

Share this post


Link to post
Share on other sites
That's not what I've ment. Nice, readable code is more important (in the long run anyways, and hey; it's ArmA we're talking about!) than a "faster" switch. Because that switch is most likely fast enough already/not a bottleneck. And if you're going to rewrite that switch-statement, maybe do some measurings first to see where your work is needed most. Otherwise you're just wasting your time.

Sure, if you're going to call that switch each frame, maybe multiple times even, we can talk about it (again, maybe try to measure it), ;). Otherwise, or in general, I wouldn't suggest to write such a call thingy that relies on find/linear search (natively implemented) just to gain a bunch of microseconds (or what?). Plus it's a lot less general, than a switch(true)-statement, where you can put any conditions/expressions you like. Find doesn't exactly work like that (granted, that call/exitWith-construct isn't too bad).

Plus: your example really looks like you want to use a hash-table/a dictionary/err... an assoc. array :wave: as a datastructure anyways. So there is no need to compare this to a switch statement. And then, maybe use a proper hash/dictionary ds, right. Then you're back(?) up to speed, and it will read nicely too! :)

Btw., I've just seen that you've got a really nice blog going over there. Keep it up! You're showing some really nice things (that uav-pip-laptop is amazing! :yay:).

Bookmarked right away!

Thank you for giving me a lesson at how to write code. FYI the array construct, despite scary looking, is almost 2 times faster than switch. So maybe you should run some speed comparison before slagging other peoples code next time.

Share this post


Link to post
Share on other sites

I'm curious to know why switch is so slow in the first place. Surely if all these other methods are faster then its implementation could be improved?

Share this post


Link to post
Share on other sites
I'm curious to know why switch is so slow in the first place. Surely if all these other methods are faster then its implementation could be improved?

Pretty sure it can be improved, lets hope there is a dev @ BI that is also optimisation fan.

Share this post


Link to post
Share on other sites
FYI the array construct, despite scary looking, is almost 2 times faster than switch. So maybe you should run some speed comparison before slagging other peoples code next time.

Well, sure. You're pretty much comparing a natively implemented linear search (find) to a linear search implemented in sqf.

This thing here:

_condition = "zzzzzzzzzzzz";
_arr = [
"aaaaaaaaaaaa",{},
"bbbbbbbbbbbb",{},
//...
"zzzzzzzzzzzz",{}
];
call (_arr select ((_arr find _condition) + 1));

...should (or can) be written as:

_key = "zzzzzzzzzzzz";
[] call ([_arr, _key] call ASSOC_ARRAY_get);

...or something.

Wouldn't you agree?

Thank you for giving me a lesson at how to write code.

uhhm.., you're welcome? :sigh:

Edited by ruebe

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×