there’s a function that I want to test the time of: function()
I am not sure how to do this in C, here’s the pseudocode of what I want to do:
int main()
{
int startTime = getTime();
function();
int endTime = getTime();
print endTime - startTime;
}
How is this done in C?
Unfortunately there is no way to do this using ANSI C. However, you can do it using
gettimeofday, a POSIX function:Alternatively, if you want the execution time of your entire program, you could also just run
time ./your_programon the command line.Finally, if you are on Windows, you can use the
timeGetTimefunction.