Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to measure code execution time?

fissyxfissyx Member Posts: 1
I have a pretty elementary question (I'm an intern - it happens!). My boss asked me to run a timer to measure how long it takes to execute some code on a Motorola 32-bit Microcontroller. I am using Metrowerks Codewarrior. Is there a built in tool in Codewarrior that can accomplish this? If there isn't, or you don't have experience using CodeWarrior, then is there a coding technique or tool that I must/can use? Any help would be greatly appreciated!

Fissyx

Comments

  • johnsonmejohnsonme Member Posts: 57
    I don't know about code warrior. But no need of using its library.. Start a timer at the starting of a particular routine.. Stop it at the end of the routine and take the time.
  • johnsonmejohnsonme Member Posts: 57
    Take the system time at the begining of the function.
    Do a simple multiplication. Execute it for one lakh times (or larger depending upon your requirment) in a for loop. After executing the for loop, take system time again. find the difference. Divide it with one lakh. you will get the time taken for one multiplication.
  • sumitxshahsumitxshah Member Posts: 20
    : Take the system time at the begining of the function.
    : Do a simple multiplication. Execute it for one lakh times (or larger depending upon your requirment) in a for loop. After executing the for loop, take system time again. find the difference. Divide it with one lakh. you will get the time taken for one multiplication.
    :



    If you are working in unix platform then there are functions " ctime(), gmtime() and localtime()", which will return you unsigned long decimal vvalue since Jan 1 1970. capture the starting and ending
    value and then subtract (closing time -opening time) this will give you the exact time in SECONDS, your program is executed.

    If you needs pression then you can also have a function which will return the value in nano-seconds. ...
    BUT you have to google for that.....I saw that function and about to use it, however, i need not have to go for such fine value, so i skip it. BUt it is definite that there is a fun with return the value in nano seconds....

    See you.

    With Regards...
    Sumit Shah.

  • LundinLundin Member Posts: 3,711
    : : Take the system time at the begining of the function.
    : : Do a simple multiplication. Execute it for one lakh times (or larger depending upon your requirment) in a for loop. After executing the for loop, take system time again. find the difference. Divide it with one lakh. you will get the time taken for one multiplication.
    : :
    :
    :
    :
    : If you are working in unix platform then there are functions " ctime(), gmtime() and localtime()", which will return you unsigned long decimal vvalue since Jan 1 1970. capture the starting and ending
    : value and then subtract (closing time -opening time) this will give you the exact time in SECONDS, your program is executed.
    :
    : If you needs pression then you can also have a function which will return the value in nano-seconds. ...
    : BUT you have to google for that.....I saw that function and about to use it, however, i need not have to go for such fine value, so i skip it. BUt it is definite that there is a fun with return the value in nano seconds....
    :
    : See you.
    :
    : With Regards...
    : Sumit Shah.
    :
    :


    How happy the original poster will be, receiving a reply only a year after posting... Always check the date before you reply.
  • madhunmadhun Member Posts: 2
    Read this link
    http://www.8052.com/tuttimer.phtml#Initializing
    It will help you sort out your doubts.
    Thanks

    : : : Take the system time at the begining of the function.
    : : : Do a simple multiplication. Execute it for one lakh times (or larger depending upon your requirment) in a for loop. After executing the for loop, take system time again. find the difference. Divide it with one lakh. you will get the time taken for one multiplication.
    : : :
    : :
    : :
    : :
    : : If you are working in unix platform then there are functions " ctime(), gmtime() and localtime()", which will return you unsigned long decimal vvalue since Jan 1 1970. capture the starting and ending
    : : value and then subtract (closing time -opening time) this will give you the exact time in SECONDS, your program is executed.
    : :
    : : If you needs pression then you can also have a function which will return the value in nano-seconds. ...
    : : BUT you have to google for that.....I saw that function and about to use it, however, i need not have to go for such fine value, so i skip it. BUt it is definite that there is a fun with return the value in nano seconds....
    : :
    : : See you.
    : :
    : : With Regards...
    : : Sumit Shah.
    : :
    : :
    :
    :
    : How happy the original poster will be, receiving a reply only a year after posting... Always check the date before you reply.
    :

Sign In or Register to comment.