I would like to calculate the time it takes (in nanoseconds) to execute a function. I know this might be a duplicate question but I could not find a solution anywhere. I already have a working calculation for milliseconds (it was taken from MSDN):
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&begin);
callfunction();
QueryPerformanceCounter(&end);
elapsed.QuadPart = (end.QuadPart - begin.QuadPart);
elapsed.QuadPart *= 1000000.0;
elapsed.QuadPart /= freq.QuadPart;
I tried doing something on the same idea to be able to achieve a nanosecond result, but to no avail. I already have this implemented in linux using the function clock_gettime().
Also the code is being written in C and not in C++.
Thanks for the help.