Page 1 of 1

How can I measure the runtime of the code?

Posted: Sun Dec 02, 2012 3:49 pm
by robu
Hi,

I'm using the following code to measure the runtime of my code

Code: Select all

start = chTimeNow();
my code
end = chTimeNow();
chprintf((BaseSequentialStream *) &SD1, "%fus\r\n", RTT2US(end - start));

I'm reciving 19 or 20 us, I never expected that my code is so fast. Am I measuring the running time in the right way?

Thanks,
Robert

Re: How can I measure the runtime of the code?

Posted: Sun Dec 02, 2012 4:19 pm
by Tectu
Your code seems right to me on the first look. However, can you paste the code you execute?


~ Tectu

Re: How can I measure the runtime of the code?

Posted: Sun Dec 02, 2012 4:20 pm
by Giovanni
The system timer has a resolution of 1uS, the RTT macro is used with the RT counter that is optionally implemented in the HAL driver (halGetCounterValue() function), I think it is not present in the RPI port, you should confirm with the author.

Giovanni