Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you measure the time a function takes to execute?

How can you measure the amount of time a function will take to execute?

This is a relatively short function and the execution time would probably be in the millisecond range.

This particular question relates to an embedded system, programmed in C or C++.

like image 908
Benoit Avatar asked Nov 26 '22 23:11

Benoit


1 Answers

The best way to do that on an embedded system is to set an external hardware pin when you enter the function and clear it when you leave the function. This is done preferably with a little assembly instruction so you don't skew your results too much.

Edit: One of the benefits is that you can do it in your actual application and you don't need any special test code. External debug pins like that are (should be!) standard practice for every embedded system.

like image 176
cschol Avatar answered Dec 05 '22 07:12

cschol