Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

176
Vistas
How much does adding functions affect the execution time?

Two codes are written to achieve the same objective. The one with more functions executed slowly compared to the other. I want to why this happens and whether it is a good practice or not.

Run this code on this website and check. - https://stanford.edu/~cpiech/karel/ide.html

Code 1(less functions):

function main(){
   beepers3Right();
   move();
   beepers2Left();
   beepers3Right();
   move();
   beepers2Left();
   beepers3Right();
}

function beepers3Right() {
   putBeeper();
   move();
   move();
   putBeeper();
   move();
   move();
   putBeeper();
   turnLeft();
}

function beepers2Left() {
   turnLeft();
   move();
   putBeeper();
   move();
   move();
   putBeeper();
   move();
   turnRight();
   move();
   turnRight();
}

Code 2(more funstions)

function main(){
   outer();
   moveDiagonal();
   inner();
   moveDiagonal();
}

function move2x(){
   move();
   move();
}

function moveStraightBeeper(){
   putBeeper();
   move2x();
}

function innerMove(){
   move2x();
   putBeeper();
   turnLeft();
}

function moveDiagonal(){
   move();
   turnLeft();
   move();
   turnRight();
   putBeeper();
}

function outerMove(){
   moveStraightBeeper();
   moveStraightBeeper();
   turnLeft();
}

function outer(){
   outerMove();
   outerMove();
   outerMove();
   outerMove();
}

function inner(){
   innerMove();
   innerMove();
   innerMove();
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda