Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

237
Visualizações
Is switch-case execution time variable?

Does switch statement determines appropriate case statement in same execution time for either of possible input values? Does it compare input value with case blocks and jumps to appropriate case when upon finding the value that it was looking for?

Consider example below. Does switch statement execute in same time for input = 1 or input = 256 or does it execute slower for latter value?

int output, input = 256;
    switch( input )
    {   
        case 1:
            output = 1;
            break;
        case 2:
            output = 2;
            break;
        case 4:
            output = 3;
            break;
        case 8:
            output = 4;
            break;
        case 16:
            output = 5;
            break;
        case 32:
            output = 6;
            break;
        case 64:
            output = 7;
            break;
        case 128:
            output = 8;
            break;
        case 256:
            output = 9;
            break;
        default:
            output = 0;
            break;
    }
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Does switch statement execute in same time for input = 1 or input = 256 or does it execute slower for latter value?

The language does not specify.

Implementations commonly implement some switch statements with the use of jump tables, which makes the switch take approximately the same amount of time regardless of the control value. However, they may also use multiple branches, exactly as for an if / else if tree, which takes a longer time to process for some control values than for others. They may use other strategies as well.

Those that choose among multiple possibilities commonly do so on the basis of the case values that must be supported.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda