timespec start, end;
float diff_time;
clock_gettime(CLOCK_REALTIME, &start);
......(측정할 코드블럭).......
clock_gettime(CLOCK_REALTIME, &end);
diff_time = (end.tv_sec - start.tv_sec) + ((end.tv_nsec - start.tv_nsec)/1000000000);
logger("%.6f second(s) elapsed.\n", diff_time);
KLDP에서 나온 예제는 이러하지만, IBM document는 좀더 참고해서 보길..
Measuring time
To measure time reliably across processors, always use CLOCK_MONOTONIC.
CLOCK_MONOTONIC always increases linearly with time. CLOCK_REALTIME, however, can change depending on changes to system time, for example, on a system running a Network Time Protocol daemon (ntpd). The following example demonstrates how to measure time using CLOCK_MONOTONIC:clock_gettime(CLOCK_MONOTONIC, &start); do_work(); clock_gettime(CLOCK_MONOTONIC, &stop);
On a platform that has high-resolution timers (HRT) enabled, measure the resolution of the clock to verify the
accuracy. Use the clock_getres call to confirm this, as follows:clock_getres(CLOCK_MONOTONIC, &tp);
Important: HRTs require both hardware support and enablement within the operating system. SUSE SLES 11.* and Red Hat Enterprise Linux 6.* distributions contain operating system support for HRTs.
The TSC clocksource is not guaranteed to be synchronized across processors, and is not a good time source for relative time measurements (unless the measured time events are within a thread that is bound to a particular processor).
Avoid using sched_yield() as it rarely leads to deterministic behavior. In a scenario where sched_yield() is called
from a high priority SCHED_FIFO process, if all other runnable threads are of lower priority, the high priority thread immediately resumes on the processor, negating the intent of calling sched_yield().
For more information about the sched_yield command, see the sched_yield command man page.
Avoid making system calls that result in I/O during latency-sensitive paths. I/O devices are generally not considered
low-latency-safe, as they may be bound by circumstances entirely outside the control of the operating system. Sometimes it is not obvious whether a particular call can lead to disk I/O. For example, a call to getpwuid() (get
password file entry) can lead to opening files on the disk if the nscd daemon is not running.
Optimize the application's use of timers as they can incur kernel overhead and can increase jitter.
For more information about the clock_getres command, see the clock_getres man page.
'$ SaVvY > » computer' 카테고리의 다른 글
const keyword in c/c++ (0) | 2013.07.10 |
---|---|
클래스라이브러리와 프레임워크. (0) | 2013.07.10 |
AIX에서 Oracle Pro*C, sqlplus 등이 실행되지 않는 경우.. (0) | 2013.07.10 |
Character Set on MySQL 5.5.xx or higher (0) | 2013.07.10 |
NCARGS : 명령행 인자 길이에 대한 커널 파라미터. (0) | 2013.07.10 |