Is it ok to post small pieces of code here that could be useful for people to include in programs?. If not, please delete or move the message.
Here is a trivial snippet of C source that will measure the time between two calls to _ftime_s() and return the number of seconds in a double, accurate to 1millisecond. It's useful for measuring run times of functions, bruteforce loops, etc, on the fly. I've used it lot, please help yourself if useful to you or ignore otherwise.
Git
Code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/timeb.h>
#include <time.h>
int main(int argc, char * argv[])
{
struct _timeb startTime, endTime;
double diftim;
_ftime_s(&startTime);
...
...
do things
...
...
_ftime_s(&endTime);
diftim = timediff(&startTime, &endTime);
printf("\nProcessing time %8.3f seconds\n", diftim);
}
double timediff(struct _timeb *timstart, struct _timeb *timend)
{
__int64 sTime, eTime;
eTime = timend->millitm + 1000 * timend->time;
sTime = timstart->millitm + 1000 * timstart->time;
return (eTime - sTime) / 1000.0;
}
// The _ftime_s(&endTime) statement could go in the timediff() function
// if the calling time of timediff() is insignificant.