How easy is it to measure the function's running time?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
mrjbom
Member
Member
Posts: 317
Joined: Sun Jul 21, 2019 7:34 am

How easy is it to measure the function's running time?

Post by mrjbom »

Hi.
I have a task to optimize the memory manager. to do this, I want to measure the performance of individual functions and parts of the code in the kernel.
What is the easiest way to implement this task?
Thanks.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: How easy is it to measure the function's running time?

Post by bzt »

mrjbom wrote:Hi.
I have a task to optimize the memory manager. to do this, I want to measure the performance of individual functions and parts of the code in the kernel.
What is the easiest way to implement this task?
Thanks.
Have a function that returns a strictly and monotonely increasing counter. This could be an absolute timestamp, but also a CPU-freq dependent counter. Both x86 and ARM has such a built-in counter, which does not rely on any peripherals. As long as all comparitions are made using the same counter, the actual unit doesn't really matter (but SI units like nanosec are better on the long run and necessary to compare your code running on different machines).

Then you use the function like this, calling it twice, before and after the code you want to measure:

Code: Select all

start = ticks();
/* ... code to be measured ... */
printf("time: %d\n", ticks() - start);
Cheers,
bzt
Post Reply