#define PROFILE_FUNCTION ProfileTimer t (__PRETTY_FUNCTION__)
// for timing stuff
class ProfileTimer
{
unsigned long start_;
const char * sReason_;
public:
// constructor remembers time it was constructed
ProfileTimer (const char * reason);
// destructor gets current time, displays difference
~ProfileTimer ();
}; // end of class ProfileTimer
ProfileTimer::ProfileTimer (const char * reason) :
sReason_ (reason)
{
Serial.print ("Start : ");
Serial.println (sReason_);
start_ = micros ();
}
// destructor gets current time, displays difference
ProfileTimer::~ProfileTimer ()
{
unsigned long interval = micros () - start_;
Serial.print ("Time taken: ");
Serial.print (sReason_);
Serial.print (" = ");
Serial.print (interval);
Serial.println (" uS.");
}
void setup ()
{
Serial.begin (115200);
} // end setup
void loop ()
{
delay (500);
ProfileTimer t ("analog read");
analogRead (A1);
/*
{
ProfileTimer t1 ("multiple reads");
for (int i = A0; i <= A5; i++)
analogRead (i);
} // end timed bit of code
*/
delay(3000);
} // end loop