Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!