printf("\n Diffence Time:%5.2fmin",difftime);
there is no variable
difftime
defined. Should this be a call to the function?
If it is a global variable, and there is a function by the same name this could get confusing for you and the compiler
I am going to assume that "exct" is a misspelling of "exact"
The following is portions of code I am using for benchmarking my thesis. It makes use of the High Precision Event Timer (HPET) which is part of modern computers. This is typically accurate to around 50-100 nanoseconds.
This code is a linux solution:
#include <time.h>
#include <stdio.h>
#include <unistd.h> //for usleep()
void TimerStart(struct timespec *pSpec) {
clock_gettime(CLOCK_REALTIME, pSpec);
}
double TimerStop(struct timespec *pSpec) {
struct timespec t;
clock_gettime(CLOCK_REALTIME, &t);
return (t.tv_sec - pSpec->tv_sec) + (t.tv_nsec - pSpec->tv_nsec) * 1.0e-9;
}
int main() {
struct timespec ts;
TimerStart(&ts);
usleep(1000000);
printf("Time taken: %2.3f microseconds\n", TimerStop(&ts) * 1000000);
return 0;
}
And this is the windows equivalent:
#include <stdio.h>
#include <Windows.h>
void TimerStart(LARGE_INTEGER *pSpec) {
QueryPerformanceCounter(pSpec);
}
double TimerStop(LARGE_INTEGER *pSpec) {
LARGE_INTEGER li, liFreq;
QueryPerformanceCounter(&li);
QueryPerformanceFrequency(&liFreq); return (li.QuadPart - pSpec->QuadPart) / (double)liFreq.QuadPart;
}
int main() {
LARGE_INTEGER ts;
TimerStart(&ts);
Sleep(1000);
printf("Time taken: %2.3f microseconds\n", TimerStop(&ts) * 1000000);
return 0;
}