How to calculate API response time in C?

Hey guys,

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);
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,


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s