了解clock_gettime()的不同时钟
您好,我想使用 clock_gettime()
函数来测量代码的性能。
我无法从手册页描述中理解该函数中使用的不同类型时钟之间的区别。 esp
CLOCK_REALTIME,
CLOCK_PROCESS_CPUTIME_ID
CLOCK_THREAD_CPUTIME_ID
有人可以解释一下这些时钟的作用吗?
Hi I wanted to use the clock_gettime()
function for measuring the performance of my code.
I am unable to understand the difference between the different kinds of clocks used in the function from the man page descriptions. esp
CLOCK_REALTIME,
CLOCK_PROCESS_CPUTIME_ID
CLOCK_THREAD_CPUTIME_ID
Can someone explaing what each of these clocks do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CLOCK_REALTIME
报告实际挂钟时间。CLOCK_MONOTONIC
用于测量相对实时时间。它以与实际时间流相同的速率前进,但不会受到系统时钟的手动或自动 (NTP) 调整的影响。CLOCK_PROCESS_CPUTIME_ID
用于测量进程消耗的CPU时间量。CLOCK_THREAD_CPUTIME_ID
用于测量线程消耗的CPU时间量。自 2.6.12 起,它就受到现代内核和 glibc 的支持,但在较旧的 Linux 内核上,glibc 通过简单地返回自线程创建以来进程消耗的 CPU 时间来模拟它。http://man7.org/linux/man-pages/man2/clock_gettime .2.html
CLOCK_REALTIME
reports the actual wall clock time.CLOCK_MONOTONIC
is for measuring relative real time. It advances at the same rate as the actual flow of time but it's not subject to discontinuities from manual or automatic (NTP) adjustments to the system clock.CLOCK_PROCESS_CPUTIME_ID
is for measuring the amount of CPU time consumed by the process.CLOCK_THREAD_CPUTIME_ID
is for measuring the amount of CPU time consumed by the thread. It's supported by modern kernels and glibc since 2.6.12, but on older linux kernels glibc emulates it badly by simply returning the amount of CPU time consumed by the process since the moment the thread was created.http://man7.org/linux/man-pages/man2/clock_gettime.2.html