Possible duplicate:C ++ timer function to ensure time in nano seconds
I need to exit the loop when approaching 3 seconds, so I need to calculate the elapsed time.
I am moving code from Java to C, and I used simple System.nanoTime () in Java,
How can I do this in C?
I noticed that time (NULL) will return seconds, but I'm looking for more accuracy.
Thank you in advance
use gettimeofday , it has a resolution in microseconds. System.nanoTime () in Java is usually implemented using gettimeofday on * nixes
clock() C :
clock()
#include <time.h> #define RUNTIME_MAX_SEC 3 clock_t start = clock(); while(clock() - start < CLOCKS_PER_SEC * RUNTIME_MAX_SEC) { ... }
Source: https://habr.com/ru/post/1733510/More articles:howto: make Tortoise Hg and Tortoise Svn coexist - version-controlHow to access values from dynaaction form in jsp - strutspython csv - data export and formatting color, text format, etc. - pythonПочему этот код компилируется в VS2005, но не VS2008 (VB.NET) - syntaxSilverlight error while passing JSON object? - jsonHow to extend the calendar on Android? - androidWeak link callback not called due to circular references - pythonperformance: sorting vectors "m" with N / m elems Vs, sorting a single vector with N elements - c ++An array of classes. Stack or heap? - c ++to compute an algorithm for storing an array element - algorithmAll Articles