How to measure a C functions execution time in ARM DS-5 under Timesys Linux?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

How to measure a C functions execution time in ARM DS-5 under Timesys Linux?

跳至解决方案
3,457 次查看
dragan
Contributor III

Respected Colleagues,

can somebody share a sample how to measure execution time inside the ARM DS-5 GCC application for Vybrid VF61 A5 core, because generic way (shown bellow) doesn't work. Variable clock_t can not be linked to a code no matter that the time.h is included. Result is always zero.

#include <time.h>

clock_t start, end;
double cpu_time_used;

start
= clock();
... /* Do the work. */
end
= clock();
cpu_time_used
= ((double) (end - start)) / CLOCKS_PER_SEC;


Thanks in advance.


With best regards,

Dragan Kujovic

标签 (3)
0 项奖励
回复
1 解答
2,441 次查看
timesyssupport
Senior Contributor II

Hello Dragan,

We have verified your code with our Timesys toolchain ,clock function works as expected. Between the two successive clock functions, if you do the work with less  than 1 unity i.e it executes in microseconds, will return zero. You can verify this with the precision of 10 floating point values in printf statement.

printf("cpu time used is %.10f \n",cpu_time_used);

Also you can try with gettimeofday() to get the execution time of your function.

Thanks,

Timesys Support

在原帖中查看解决方案

0 项奖励
回复
4 回复数
2,442 次查看
timesyssupport
Senior Contributor II

Hello Dragan,

We have verified your code with our Timesys toolchain ,clock function works as expected. Between the two successive clock functions, if you do the work with less  than 1 unity i.e it executes in microseconds, will return zero. You can verify this with the precision of 10 floating point values in printf statement.

printf("cpu time used is %.10f \n",cpu_time_used);

Also you can try with gettimeofday() to get the execution time of your function.

Thanks,

Timesys Support

0 项奖励
回复
2,441 次查看
dragan
Contributor III

Thanks for your answer.

I think that something is wrong with project and compiling from ARM DS-5, because the variable clock_t is red underscored, but compiling pass without errors and warnings. time.h is included.

When I try from Linux shell "time sleep 2" it returns correct answer, but when I try it from application with reading

start = clock();

sleep(2); // 2 seconds

end = clock();

both start and end are populated with the same value, and because of that the result is allways zero.

I will try to further investigate this.

With best regards,

Dragan Kujovic

0 项奖励
回复
2,441 次查看
alejandrolozan1
NXP Employee
NXP Employee

Hi Dragan,

" I think that something is wrong with project and compiling from ARM DS-5, because the variable clock_t is red underscored, but compiling pass without errors and warnings. time.h is included."

Those problems in DS-5 are due the IDE is not able to find some symbols. You have to #include the correct file including the path.

Best Regards,

Alejandro

0 项奖励
回复
2,441 次查看
karina_valencia
NXP Apps Support
NXP Apps Support

timesyssupport can you help with this case?

0 项奖励
回复