• @user85573, thank you very much for you effort... (and mending the t0... copy/paste shoving code around tripped me... and still is. May be does not matter because the times as captured by you show already a nice difference...) My intensions for timing instrumentation are never to include console out... but I missed that part too. The correct code for 2(b) would be more along these lines:

    Variation 2(b))

    // V2b - flash an 8 LED neopixel array in a rainbow pattern
    var neo = require("neopixel");
    var led_count = 8;
    var neoPin = NodeMCU.D4;
    var rgb = new Uint8ClampedArray(led_count * 3);
    var len = rgb.length;
    var m = 127;
    var r = 0.1324*m;
    var g = 0.1654*m;
    var b = 0.1*m;
    var pos = 0;
    function getPattern() {
      var t0 = getTime();
      pos++;
      for (var i=0; i<len;) {
        rgb[i++] = m + Math.sin((i+pos)*r;
        rgb[i++] = m + Math.sin((i+pos)*g;
        rgb[i++] = m + Math.sin((i+pos)*b;
      }
      console.log(getTime() - t0);
      return rgb;
    }
    function bow() {
      neo.write(neoPin, getPattern());
    }
    function onInit() {
      setInterval(bow,200); // may need to change to allow console to write
    }
    setTimeout(onInit, 1000);
    

    I was missing line 13 completely and line 20 I should have made to read:

    t0 = getTime() - t0;
    console.log(t0);
    

    But anyway, thanks for timing it for me.

    Conclusion is that doing some optimization to prevent (source code) interpreter to do some things all over again saved about 20..25%. The numbers also show that the write is practically neglectable compared to the trigonometric calculations.

About

Avatar for allObjects @allObjects started