Hi,
What is the best way of measuring the execution time of a function with nanosecond precision on MQX 4.1?
What I have in mind is something like
uint32_t start = get_time ();
f();
uint32_t delta = get_time () - start;
However, _time_get_nanoseconds () does not work for me because there is a timer interrupt during the execution of f().
Any ideas?
Regards,
Michael
If possible, you could try to set a IO pin high before execute the funtion, set to low after the function. Use scope to measure the IO pin, this is the way I used.
Hi Michael,
I think using the timeget_elapsed_ticks() function would work as it has the number of TICKS (5 msec) in a 64-bit variable since the beginning of MQX execution as well as a HWTICKS variable which is the number of hardware ticks that have occurred since the last TICK.
Calling it before and after your f(); should give you the time.
Please also look at this post:
https://community.freescale.com/thread/334266
Hope this helps.
Regards,
David
Hi David,
Thank you for your response. Unfortunately, the resolution of your solution is only 5 milliseconds whereas I need microsecond (or better, nanosecond) precision.
Kind regards
Michael
Hi Michael,
Please have a look at my modified lwevent project source code attached to see if this resolves your issue.
My terminal output looks like:
Tick
0Min:1Sec:999ms:998751us:998750808ns
Tick
0Min:2Sec:2217ms:2216541us:2216541475ns
Tick
0Min:2Sec:2771ms:2771294us:2771293975ns
Tick
0Min:3Sec:3326ms:3326289us:3326289333ns
Tick
0Min:1Sec:1661ms:1661286us:1661285900ns
Tick
0Min:3Sec:3881ms:3881293us:3881292742ns
Tick
0Min:0Sec:551ms:551269us:551269458ns
Tick
0Min:4Sec:4437ms:4436523us:141555812ns
Tick
0Min:1Sec:1106ms:1106352us:1106351800ns
Tick
0Min:4Sec:4991ms:4991266us:696298787ns
Tick
0Min:0Sec:996ms:996351us:996350950ns
Regards,
David
Hi Michael,
Please check the below thread
Change MQX periodic timer period?
Have a great day,
Sol
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------