I found this site

http://www.guyrutenberg.com/2007/09/22/profiling-code-using-clock_gettime/

If I have a server-client code and this:

clock_gettime(CLOCK_REALTIME, &time_a); // create socket
clock_gettime(CLOCK_REALTIME, &time_b); // close socket

If I have a and b wand want to measure the time it takes to communicate, what's the best way ? Still not fully understanding the exact difference between

CLOCK_REALTIME
CLOCK_PROCESS_CPUTIME_ID
CLOCK_THREAD_CPUTIME_ID

And there are a few others.

if you have a compiler that support c++11 check this out. It will show you how to use the high resolution clock available in c++11.

Thank you. So it dosen't really matter which one I use ? I don't understand the difference.

Well the different choices are for which clock to use. CLOCK_REALTIME uses the full system time. CLOCK_PROCESS_CPUTIME_ID uses the time in the process and CLOCK_THREAD_CPUTIME_ID uses the time from the thread. If you have c++11 I would really suggest using the high resolution clock from the chrono header.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.