Portable method of getting time in C
A few notes:


clock_gettime() is not standard C, which means it's not guaranteed to be implemented on any system that supports C (including many Linux platforms, the few who implement it stuff it into time.h, but there are only a handful of standardized functions in that header). Relying on it for "portability" is not something you should do.
There is no standard C function that provides better than 1 second time resolution, but the POSIX function gettimeofday() provides microsecond resolution.

You can use this function like this:

struct timeval before = {};
struct timeval after = {}; 
struct timeval result = {};

gettimeofday(&amp;before, NULL);

// Some code you want to time

gettimeofday(&amp;after, NULL);
timersub(&amp;after, &amp;before, &amp;result);

printf("Time elapsed: %ld.%06ld\n", (size_t) result.tv_sec, (size_t) result.tv_usec);

The other option is to just use the clock() function in time.h which is part of the C standard, but as stated before the time resolution is not great.
Please don't use busy waiting (side note: that would be a place for a for loop, not a while loop).  It's wasteful of CPU resources and could even be optimized out by the compiler.  It would be much more efficient and easier to test your code with the sleep() function as then you know how many seconds long the process should take.  If you want different resolutions for causing the current thread to be suspended from execution of your code, take a look at usleep() or nanosleep().