You are reading a single comment by @JumJum and its replies. Click here to read the full conversation.
  • Gave it a new try and got these numbers:
    blinker object only, usage 50, history 37
    3 blinker with object, usage 158, history 49
    3 blinker with object, minified from 504 to 386, usage 149, history:31
    3 blinker with require, usage 192, history:55
    From my best understanding

    • the blinker object itself takes a few bytes only
    • each instance with 4 variables(pin,duration,interval,status) takes around 600 bytes
    • minifying reduces some bytes
    • require takes more memory than an object
      Is there anything wrong with my interpretation ?

      
      function Blinker(pin,frequency){
      this.interval = 0;
      this.status = true;
      this.duration = 1000 / frequency;
      this.pin = pin;
      this.start();
      }
      Blinker.prototype.start = function(){
      var me = this;
      me.interval = setInterval(function(){
      me.status = !me.status;
      me.pin.write(me.status);
      },me.duration);
      };
      Blinker.prototype.stop = function(){
      this.pin.write(false);
      clearInterval(this.interval);
      };
      var b = new Blinker(LED1,2);
      var c = new Blinker(LED2,5);
      var d = new Blinker(LED3,7);
      
      
About

Avatar for JumJum @JumJum started