I’m here just to describe how we can calculate our API response time in C. When I say response time, I wanna mean the time that the API spend to do some process. This time is calculated by considering the difference time between before function call and after it. Look this example:
#include <time.h> struct timeval before, after, diff; double diff_ms, before_ms, after_ms; gettimeofday(&before, NULL); call_function_f(); gettimeofday(&after, NULL); before_ms = (before.tv_sec + before.tv_usec/1000000.0) * 1000; /* time unit in ms */ after_ms = (after.tv_sec + after.tv_usec/1000000.0) * 1000; /* time unit in ms */ diff_ms = after_ms - before_ms;
So, in this example we get the response time (diff_ms) of the function named call_function_f.
Until next time,