计算时间在Linux中:粒度和precision [英] Computing time in linux :granularity and precision

查看:350
本文介绍了计算时间在Linux中:粒度和precision的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用不同的时钟,以获得在Linux系统时间:

I am using different kind of clocks to get time in LINUX systems :

RDTSC,gettimeofday的,clock_gettime

rdtsc, gettimeofday, clock_gettime

和已经读过各个线程这样的:

and already read various threads like these :

<一个href=\"http://stackoverflow.com/questions/12643535/whats-the-best-timing-resolution-can-i-get-on-linux\">What's最好的定时分辨率可以让我在Linux上

<一个href=\"http://stackoverflow.com/questions/13230719/how-is-the-microsecond-time-of-linux-gettimeofday-obtained-and-what-is-its-acc\">How得到的linux的gettimeofday的微秒时间(),什么是它的准确性?

如何测量的时间间隔用C <? / A>

How do I measure a time interval in C?

更快相当于gettimeofday的

粒度在时间功能

为什么这么clock_gettime飘忽不定?

但我有点困惑:

粒度(或分辨率或precision)精度是不一样的东西(如果我是正确的......)

Granularity(or resolution or precision) and accuracy are not the same things (if I am right ...)

例如,在使用的clock_gettime的precision为10ms,因为我用得到:

For example, while using the "clock_gettime" the precision is 10ms as I get with:

struct timespec res;
clock_getres( CLOCK_REALTIME, &res):

和粒度(其定义为每秒蜱)为100Hz(或10毫秒),因为我得到执行时:

and the granularity (which is defined as ticks per second) is 100Hz(or 10ms), as I get when executing :

 long ticks_per_sec = sysconf(_SC_CLK_TCK); 

精度在纳秒级,为上述code提示:

Accuracy is in nanosecond, as the above code suggest :

结构的timespec gettime_now;

struct timespec gettime_now;

clock_gettime(CLOCK_REALTIME,&安培; gettime_now); TIME_DIFFERENCE =
  gettime_now.tv_nsec - START_TIME;

clock_gettime(CLOCK_REALTIME, &gettime_now); time_difference = gettime_now.tv_nsec - start_time;

在下面的链接,我看到了,这是粒度的全球Linux定义,最好不要去改变它:

In the link below,I saw that this is the Linux global definition of granularity and it's better not to change it:

http://wwwagss.informatik.uni-kl.de/Projekte/Squirrel/da/node5.html#fig:clock:hw

所以我的问题是,如果高于这个言论是正确的,也:

So my question is If this remarks above were right, and also :

一),我们可以看到的是RDTSC和gettimeofday的粒度(带命令)?

a) Can we see what is the granularity of rdtsc and gettimeofday (with a command)?

b)我们可以改变它们(任何方式)?

b) Can we change them (with any way)?

在此先感谢

大家好,我已经测试了一些新的时钟,我会和大家分享相关信息:

Hi all , I have tested some new clocks and I will like to share infos :

a)在页面下方, 大卫Terei ,做过细的程序,比较了各种时钟和他们的表演:

a) In the page below, David Terei, did a fine program that compares various clock and their performances :

https://github.com/dterei/Scraps/tree/master/ C /时间

二)我还测试的 omp_get_wtime Raxman 按建议,我发现了一个precision在纳秒,但不是真的好不是clock_gettime(因为他们在本网站所做的):

b) I have also tested omp_get_wtime as Raxman suggested by and I found a precision in nsec, but not really better than "clock_gettime(as they did in this website) :

http://msdn.microsoft.com/en-us/library/ t3282fe5.aspx

我觉得这是一个面向窗口时间功能

I think it's a window oriented time function

更好的结果给定的 clock_gettime 使用使用CLOCK_REALTIME时比CLOCK_MONOTONIC。那是正常的,因为首先计算的处理时间和其他的实时分别为

Better results are given with clock_gettime using CLOCK_MONOTONIC than when using CLOCK_REALTIME . Thats normal, because the first calculates PROCESSING time and the other REAL TIME respectively

三)我也发现英特尔功能的 ippGetCpuClocks ,但不是因为它的强制先注册我已经没有测试它:

c) I have found also the Intel function ippGetCpuClocks, but not I ve not test it because it's mandatory to register first :

http://software.intel.com/en-us/articles/ipp-downloads-registration-and-licensing/

...或者你可以使用试用版

... or you may use a trial version

感谢所有您的答复!

推荐答案


  • precision 的是信息的数量,即你报显著位数。 (例如,我是2M,1.8米,1.83米,1.8322米高。所有这些测量是准确的,但越来越多的precise。)

  • Precision is the amount of information, i.e. the number of significant digits you report. (E.g. I am 2m, 1.8m, 1.83m, 1.8322m tall. All those measurements are accurate, but increasingly precise.)

    精度的是报告的信息和事实真相之间的关系。 (例如,我身高1.70米更precise不是1.8米,但实际上并不准确。)

    Accuracy is the relation between the reported information and the truth. (E.g. "I'm 1.70m tall" is more precise than "1.8m", but not actually accurate.)

    粒度解决方法的是阿布的最小时间间隔计时器可以测量。例如,如果你有1ms的粒度,几乎没有报告点纳秒precision的结果,因为它不可能是精确到precision的那个级别。

    Granularity or resolution are abou the smallest time interval that the timer can measure. For example, if you have 1ms granularity, there's little point reporting the result with nanosecond precision, since it cannot possibly be accurate to that level of precision.

    在Linux中,随着粒度可用的定时器是:

    On Linux, the available timers with increasing granularity are:


    • 时钟()&LT; time.h中&GT; (?20毫秒或10毫秒的分辨率)

    • clock() from <time.h> (20ms or 10ms resolution?)

    函数gettimeofday()从Posix的&LT; SYS / time.h中&GT; (微秒)

    gettimeofday() from Posix <sys/time.h> (microseconds)

    clock_gettime()在POSIX(纳秒?)

    clock_gettime() on Posix (nanoseconds?)

    在C ++中,&LT;计时&GT; 头提供了解决这个一定量的抽象,而的std :: high_resolution_clock 试图给你最好的时钟。

    In C++, the <chrono> header offers a certain amount of abstraction around this, and std::high_resolution_clock attempts to give you the best possible clock.

    这篇关于计算时间在Linux中:粒度和precision的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆