Dear David, Thanks for the suggestion, IT WORKED!
latency reduced to 4 uSec that's huge. and yes, I made mistake in pasting the code and removing the comments. Thanks a ton. Reposting the code bellow: #include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> int main() { struct timespec sT, eT clock_gettime(CLOCK_REALTIME, &sT); // printf("\n%ld.%09ld\n" ,sT.tv_sec,sT.tv_nsec); clock_gettime(CLOCK_REALTIME, &eT); printf("\n%ld.%09ld %ld uSec\n" , eT.tv_sec, eT.tv_nsec, ((eT.tv_sec - sT.tv_sec)*1000000 +(eT.tv_nsec-sT.tv_nsec)/1000)); return 0; } Regards, Rathin On Friday, May 19, 2017 at 12:10:10 PM UTC+5:30, David McQuate wrote: > > I suggest you call clock_gettime () twice with nothing between these > calls. printf() is a complicated function that may interact with hardware, > for example, a serial port or ethernet. The time required to do input or > output may depend on the state of the hardware, or on the operation of a > queue, or maybe even task switching that happens when the system waits for > I/O. > > ( I don't see the definition of sT and eT. Are they declred as pointers > to startTIme and stopTime ?) > > > Rathin Dholakia <rathind...@gmail.com <javascript:>> wrote: >> >> Dear All, >> >> I was experimenting with the timing and timing accuracy on BBB. and I >> came across a very *interesting* yet strange thing! >> >> Just running clock_gettime()twice and measuring the time difference, >> gives you horrendous timing. Here is my simple C code: >> >> #include <stdio.h> >> #include <stdlib.h> >> #include <math.h> >> #include <time.h> >> >> >> int main()! >> { >> >> >> struct timeval startTime, stopTime; >> >> >> clock_gettime(CLOCK_REALTIME, &sT); >> printf("\n%ld.%09ld\n" ,sT.tv_sec,sT.tv_nsec); >> >> clock_gettime(CLOCK_REALTIME, &eT); >> printf("\n%ld.%09ld %ld uSec\n" , eT.tv_sec, eT.tv_nsec, ((eT.tv_sec >> - sT.tv_sec)*1000000 + (eT.tv_nsec-sT.tv_nsec)/1000)); >> >> >> return 0; >> } >> >> Just two gettime are causing *2894 to 3200 micro sec* (uSec) time >> difference, how is such huge amount possible!?? >> >> Can someone throw some light on this? and can it be improved or fixed? >> >> I have tried the following to investigate. >> >> 1) Running same code on my i7 >> it gives 80uS to ~300 uS delay. >> >> 2) Trying TimeVal and GetTimeOfDay -- gives worse result! >> >> 3) Running NTP: >> No impact. >> >> Thank you, and hope you find it interesting as well :) >> >> -- >> For more options, visit http://beagleboard.org/discuss >> --- >> You received this message because you are subscribed to the Google Groups >> "BeagleBoard" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to beagleboard...@googlegroups.com <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/beagleboard/7d0c12ca-1e1a-4754-9b30-8f1a75c1dc6c%40googlegroups.com >> >> <https://groups.google.com/d/msgid/beagleboard/7d0c12ca-1e1a-4754-9b30-8f1a75c1dc6c%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > Sent with mySecureMail. > http://www.mysecurephone.eu/ -- For more options, visit http://beagleboard.org/discuss --- You received this message because you are subscribed to the Google Groups "BeagleBoard" group. To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/6b4dccbf-2a17-407d-b927-e6d3abcb833f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.