// STEP ONE : Install LC_baseTools using the library manager.
//
// STEP TWO : Copy this c++ class to your .ino file..
// 
// VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV

#include <strTools.h>


// ********** Function timer class.. ************

class fxTimer {

  public:
    fxTimer(const char* fxName);
    ~fxTimer(void);

  private:
    char*         name;
    unsigned long startMicros;
};


fxTimer::fxTimer(const char* fxName) {

  name = NULL;              // Let's not time ourselves..
  heapStr(&name,fxName);    // 
  startMicros = micros();   // So we start here.
}


fxTimer::~fxTimer(void) {

  Serial.print(micros()-startMicros); // Grab time as the first of the last..
  Serial.print(" micros\t");          // And then just close down shop.
  Serial.println(name);               //
  freeStr(&name);                     //
}

//Handy define to put in your functions..
#define TIME fxTimer time(__func__);

// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// END OF COPIED CLASS.
// **********************************************




// ********** Example sketch.. *************

void setup() {

  Serial.begin(115200);
  Serial.println("Time some stuff.");
  function1();
  function2();
  function3();
}


// STEP THREE Add TIME as the first line of any function
// you would like to time.  And..
void function1(void) {
  TIME  // This makes the magic happen!

  delay(20);
}


void function2(void) {
  TIME  // Any function you want to time.

  delay(40);
}


void function3(void) {
  TIME  // You just add this as the first line.

  function1();
  function2();
  GIANT_RAT_FUNCTION(3);
  delay(100);
}


void GIANT_RAT_FUNCTION(int numRats) {
  TIME 

  delay(200);
  delay(100);
}


void loop() {
  // put your main code here, to run repeatedly:

}