Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21592 Discussions

Confirmation about method of calulate execution time

Altera_Forum
Honored Contributor II
1,506 Views

Hi  

 

I try to check the execution time of my algorithme. I use the high res_timer. I find on the tutorial how can calculate it, at least with this instruction: 

time1= alt_timestamp(); 

K=1; 

time2= alt_timestamp(); 

num_ticks=time2-time1; 

printf("execution time en ms is : %.*f (ms)\n",4, (((float)num_ticks/(float)alt_timestamp_freq())*(float)1000)); 

 

And when i try to calculate the execution time for just simple instruction (k=1) i don't find one clock cycle. 

 

The frequency that i use is 250 Mhz. It mean that for execute (k=1) instruction should be 0.004 microsecond but i find 0.4 microsecond. 

That's mean there are a factor of 100.  

 

My question is there are mistake on the method?  

Or i should devide the time by 100? 

Or what is the problem? 

 

Thank you
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
622 Views

Throwing time snapshots around a single instruction isn't going to yield any answer besides 0. The timer resolution isn't fine grain enough to count clock cycles. Typically you measure the time for a criticial section of code and if that's too short you throw it into a loop to measure an average time per loop iteration. 

 

You could create a timer core with a resolution of a clock cycle to measure something like k=1; but to be honest it doesn't seem like something worth doing..... 

 

if you want to debug your measuring technique why not just put a usleep() call in there for a significant amount of time and see if the measured value is in the same ballpark as the sleep time you passed into usleep()?
0 Kudos
Altera_Forum
Honored Contributor II
622 Views

Thank you for your reply, ok i will check you method and inform you. 

Thanks
0 Kudos
Altera_Forum
Honored Contributor II
622 Views

 

--- Quote Start ---  

Throwing time snapshots around a single instruction isn't going to yield any answer besides 0. The timer resolution isn't fine grain enough to count clock cycles. Typically you measure the time for a criticial section of code and if that's too short you throw it into a loop to measure an average time per loop iteration. 

 

You could create a timer core with a resolution of a clock cycle to measure something like k=1; but to be honest it doesn't seem like something worth doing..... 

 

if you want to debug your measuring technique why not just put a usleep() call in there for a significant amount of time and see if the measured value is in the same ballpark as the sleep time you passed into usleep()? 

--- Quote End ---  

 

 

Ok your idea it is very good. I use usleep and the method that i mentionned give a good result. 

THank you
0 Kudos
Altera_Forum
Honored Contributor II
622 Views

When measuring instruction performance a simulation is probably the most appropriate way to determine the time. The cycle counts for the Nios II processor are documented in the hardware handbook so if that's all you were looking to do then I would just look them up. 

 

If you plan on measuring critical sections of code and want more timer resolution then I would take a look at the performance counter component. It'll measure a few criticial sections with clock cycle resolution.
0 Kudos
Reply