Measuring code execution Period


hi all,

i have atmega328p board , want measure number of cycles code takes. so,
quote
1. using millis() @ 2 points , calculating time taking difference. correct method?

quote
2.after calculating time, multiplying 16mhz(assuming default frequency @ atmega328p runs)  to calculate number of clockcycles. not sure whether getting true cycles??



here code:
code: [select]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <avr/pgmspace.h>
#include "cubehash.h"

long starttime ;                    // start time stop watch
long elapsedtime ;                  // elapsed time stop watch
int fractional;                     // variable used store fractional part of time



void setup(){
   serial.begin(9600);
    starttime = millis();

   int i,ret_val;
//   serial.flush();
   serial.println("start");
////basically want calculate execution period of
/////function gebshortmsg(224);
   ret_val=genshortmsg(224);

  elapsedtime =   millis() - starttime;
                           // store buttonstate in lastbuttonstate, compare next time
  serial.print( (long )(elapsedtime / 1000l));         // divide 1000 convert seconds - cast int print
   
    serial.print(".");                             // print decimal point
        
       // use modulo operator fractional part of time
    fractional = (long)(elapsedtime % 1000l);
    if (fractional == 0)
       serial.print("000");      // add 3 zero's
     else if (fractional < 10)    // if fractional < 10 0 ignored giving wrong time, add zeros
       serial.print("00");       // add 2 zeros
     else if (fractional < 100)
       serial.print("0");        // add 1 zero
   
    serial.println(fractional);  // print fractional part of time
     serial.println("");


 
}





void loop()
{

}
////////////then here function definitions


--thnaks
--arpan

quote
. using millis()

micros might better.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Measuring code execution Period


arduino

Comments