You are reading a single comment by @MaBe and its replies. Click here to read the full conversation.
  • There has been a lot talking about loop performance.

    So lets's try to find out if there is a difference between loops and loops.

    Tested on an original Espruino board so others may differ for the time but not for the result.

    VERSION: "2v05",
    GIT_COMMIT: "990dac35",
    BOARD: "PICO_R1_3",

    Test code snipped with for, while and do.

    var LOOPS = 1E4;
    function forLoop(){
          for (i = 0; i < LOOPS; i++) {
              x = 0;
    function whileLoop(){
          var i = LOOPS;
          while (i) {
    function doLoop(){
          var i = LOOPS;
          do {
          } while(i);
    function run(f){
          ts = getTime();
          te = getTime();
          return te - ts;


    // result time is in seconds

    As a result: Try to use do or while loops instead of for loops , they run nearly twice as long.


Avatar for MaBe @MaBe started