clock() or gettimeofday() or ippGetCpuClocks()?

Published:04/14/2010   Last Updated:04/14/2010

When using IPP, mainly the three different functions used by users to measure timing of a computation or an application or a function in Intel® IPP are clock(), gettimeofday() and ippGetCpuClocks(). Details of each function are listed below and why you should be using ippGetCpuClocks() in your IPP applications instead of clock() or gettimeofday().

clock():   The granularity of clock() function is dependent on implementation by various compiler vendors.  The C standard does not say anything about the granularity of clock() - a compiler can have it check time once a second and increment the variable by CLOCKS_PER_SEC. This means it is possible that, depending on different compiler implementation, you can get zero, CLOCKS_PER_SEC, CLOCKS_PER_SEC * 2 and so on, never getting any intermediate value. Don't use clock() if you need high granularity.

gettimeofday():  It returns time in milliseconds or the wall clock time. The precision of gettimeofday is also very bad, for example, for a 3 GHz machine that means precision == 3 million of cpu clocks only. If your application does only calculations, clock() and gettimeofday() would be fairly close. Any time, if the application starts waiting for something  (for  e.g: DISK  I/O), clock() will lag behind  compared to the gettimeofday().  clock() can also go faster than gettimeofday() if you have multiple threads running in the same process.

ippGetCpuClocks():  The IPP function ippGetCpuClocks() provides precision equals to 1 cpu clock.  If you want to get the highest granularity or precision, we highly recommend you to use ippGetCpuClock(). This can be used even your program is parallel and runs on multiple cores - all TSC counters are synchronized and show the same clocks as like there is the only one counter in a system.

Product and Performance Information


Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804