On Thu, 2009-02-19 at 17:11 +0100, Dimitri Holz wrote:
> Which control structure is faster inside a loop (for, while or do-while)?

switch is probably faster because the compiler can use a lookup table.
But the compiler maybe optimizes the if version to do the same as the
switch version anyway. That's only theoretical, though. If you want to
know for sure, you should profile your code.

> 1)----------------------------------------------------------
> 
>         switch(x)
>         {
>                case 1:
>                {
>                    .....    ;
>                    break;
>                 }
>                 case 2:
>                 {
>                    ....    ;
>                    break;
>                 }
>          }
> 
> 2)---------------------------------------------------------
> 
>  
>           if(x = = 1)
>           {
>                 ........ ;
>                 break;
>           }
>           if(x = = 2)
>           {
>                 ........;
>                 break;
>           }

Armin

_______________________________________________
gtkmm-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Reply via email to