C++ 了解clock_gettime()的不同时钟

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7506952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 17:03:21  来源:igfitidea点击:

Understanding the different clocks of clock_gettime()

c++cclock

提问by smilingbuddha

Hi I wanted to use the clock_gettime()function for measuring the performance of my code.

嗨,我想使用该clock_gettime()函数来衡量我的代码的性能。

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?

有人可以解释每个时钟的作用吗?

回答by R.. GitHub STOP HELPING ICE

CLOCK_REALTIMEreports the actual wall clock time.

CLOCK_REALTIME报告实际挂钟时间。

CLOCK_MONOTONICis 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_MONOTONIC用于测量相对实时。它以与实际时间流相同的速度前进,但不受手动或自动 (NTP) 调整系统时钟的影响。

CLOCK_PROCESS_CPUTIME_IDis for measuring the amount of CPU time consumed by the process.

CLOCK_PROCESS_CPUTIME_ID用于测量进程消耗的 CPU 时间量。

CLOCK_THREAD_CPUTIME_IDis 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 processsince the moment the thread was created.

CLOCK_THREAD_CPUTIME_ID用于测量线程消耗的 CPU 时间量。自 2.6.12 以来,现代内核和 glibc 都支持它,但在较旧的 linux 内核上,glibc 通过简单地返回自线程创建以来进程消耗的 CPU 时间量来严重模拟它。

http://man7.org/linux/man-pages/man2/clock_gettime.2.html

http://man7.org/linux/man-pages/man2/clock_gettime.2.html