• arr = new Uint8Array(1000);
    for (var i in arr) arr[i] = Math.random()*256;
    
    function slow(b,c) { 
      return b + c;
    }
    
    function fast(b,c) { 
      "compiled";
      return b + c;
    }
    
    function test() {
      t = getTime();
      console.log(arr.reduce(slow));
      console.log("Slow = ",getTime()-t);
    
      t = getTime();
      console.log(arr.reduce(fast));
      console.log("Fast = ",getTime()-t);
    }
    
    test();
    

    gives:

     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v72 Copyright 2014 G.Williams
    >echo(0);
    129986
    Slow =  0.21045684814
    129986
    Fast =  0.03233909606
    

    And that's just the start...

  • Hi Gordon,
    I'am playing with the compiled functions and my Espruino (1v75) based on your code from post #9 outputs the following:
    ...
    echo(0);
    129297
    Slow = 0.23056221008
    91078231610832719163859600607397376772912088895903881996317739501
    Fast = 0.05572032928
    =undefined
    ...
    I have also tried division, multiplication and even substraction and all return different values for "slow" and "fast". I have also tried both online and offline (git) compiler with the same results. Am I doin' smtg wrong ?

About

Avatar for user54205 @user54205 started