I only know the GNU C library specific functions and haven't checked if they can be used on windows via MinGW, but I'm sure there is some native equivalent there. You want a function that will report the time at the level of milliseconds, and do something like this:
Code:
#include <stdio.h>
#include <sys/timex.h>
void reportTimeDif (struct ntptimeval *a, struct ntptimeval *b) {
long mic = b->time.tv_usec - a->time.tv_usec,
sec = b->time.tv_sec - a->time.tv_sec;
if (mic < 0) {
sec--;
mic *= -1;
mic++;
}
printf("Elapsed: %ld microseconds\n", mic + sec * 1000000);
}
#include <unistd.h> // for sleep call
int main (void) {
struct ntptimeval start, end;
ntp_gettime(&start);
sleep(3); // your function call here
ntp_gettime(&end);
reportTimeDif(&start, &end);
return 0;
}
Elapsed: 3000170 microseconds
This is in microsecond because that's what ntptimeval uses, but you should aim to round that off to whole milliseconds. Ie, if your result was "562 microseconds", or 0.5 ms, don't trust that measurement, the scale is too small (the OS kernel is unlikely to report that accurately). Instead, execute the function over and over again in a for loop, measuring the for loop, and divide. For simple functions, you may have to execute thousands or hundreds of thousands of times.
There are also tools called profilers that can report this kind of information, altho that is not their primary purpose and they may introduce inaccuracies with regard to the objective time because they slow execution down slightly, I believe (they are intended to compare relatively, ie, what percentage of the overall execution time is spent doing x y and z).