Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

Using Timestamp to measure code execution time

I'm trying to measure the time taken in seconds for a section of my c-code to execute. I've followed the instructions from the Nios handbook - Chapter 6 - Example 6-9 as below


if (alt_timestamp_start()< 0)
     {
       printf ("No timestamp device is available.\n");
     }
  
time1 = alt_timestamp();
func(); //function being monitored
time2 = alt_timestamp();
 printf("timestamp value = %u ticks\n",
              (unsigned int) (time2 - time1));
 

If I want to get the actual time taken in seconds, do I just divide the timestamp value by alt_timestamp_freq()?

I have added the Interval Timer component in SOPC with default parameters. How do these parameters affect my actual time? I read the 'Interval Timer Core' documentation but I am not sure if I have to change any setting for my usage.

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    OK, I found what I was looking for. Please ignore post above. Sorry.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Could you please show me how to use it to calculate the performance of C code run on Nios ?

    Thanks,

    Khai.