是的boost ::了posix_time :: microsec_clock CPU密集型? [英] Is boost::posix_time::microsec_clock CPU intensive?

查看:909
本文介绍了是的boost ::了posix_time :: microsec_clock CPU密集型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得与使用Boost毫秒precision的时间。 (精度并不需要是毫秒,只是接近)。

I would like to obtain the time with millisecond precision using Boost. (The accuracy does not need to be millisecond, just close.)

参照当地时间与毫秒和其他人,这是表明微秒时钟应使用

Referring to Local time with milliseconds, and others, it is indicated that the microsecond clock should be used:

boost::posix_time::microsec_clock::local_time();

在我的经验,这是不可能获得与标准时间以微秒precision(假设一些类似的精度),低影响的系统调用(即 :: GetTicks() 在Windows上)。相反,CPU密集型的调用需要发给提高精度超越毫秒(到微秒)。

In my experience, it is impossible to obtain time to a precision of microseconds (assuming some similar accuracy) with the standard, low-impact system calls (i.e., ::GetTicks() on Windows). Rather, CPU-intensive calls need to be issued to improve the accuracy beyond milliseconds (into microseconds).

正如我所说,我并不需要微秒precision - 只是有点接近毫秒precision。然而,的Boost.Date_Time不提供任何millisec_clock - 它提供了一个 second_clock ,下一个层次是 microsec_clock ,中间没有millisec_clock。

As I mentioned, I don't need microsecond precision - just somewhat close to millisecond precision. However, Boost.Date_Time does not provide any "millisec_clock" - it provides a second_clock, and the next gradation is microsec_clock, with no "millisec_clock" in between.

如果我使用 microsec_clock ,如上所述,获得毫秒,我会用一个CPU密集型的电话打?

If I use the microsec_clock, as noted, to obtain MILLIseconds, will I be hit with a CPU-intensive call?

推荐答案

我也用来衡量一个函数内部花费的时间,使用boost :: date_time的对象和especifically我用microsec_clock :: LOCAL_TIME()辅助对象。

I did a helper object used to measure time spent inside a function, using boost::date_time objects and especifically I used microsec_clock::local_time().

我使用这个对象来衡量一个几百万不同功能的快速调用(压力测试情况下),并suddently我开始注意到,我无法解释我的过程中的执行时间很多。一些实验后,我取消了大部分这些计数器和我的code的总执行时间从去〜23分钟约〜12分钟(约50%!)

I was using this object to measure a couple million quick calls to different functions (a stress test case) and suddently I started to note that I could not account for a LOT of the execution time of my process. After some experiments i removed most of these counters and the total execution time of my code went from ~23 mins to about ~12 mins (about 50% !!)

所以,从我的经验,回答你的问题,microsec_clock :: LOCAL_TIME()是昂贵的。

So, to answer your question from my experience, microsec_clock::local_time() IS EXPENSIVE.

看到这个之后,我确实使用microsec_clock :: universal_time()的测试,而不是microsec_clock :: LOCAL_TIME(),它肯定是我的运行时间改善。它仍然增加了大约3分钟,但超过10分钟更好:P。关于它的思考,我想这个问题是LOCAL_TIME()抵消了时间值占时区,这在我的情况下,没有必要(因为我只在所需的时间差异)。我还是要进行测试,以检查是否有其他方法更快(如clock_gettime)。

After seeing this I did a test using microsec_clock::universal_time() instead of microsec_clock::local_time() and it was definitely an improvement for my run time. It still added about 3 minutes, but it is better than 10 minutes :P. Thinking about it, i guess the problem is that local_time() offsets the time value to account for the time zone, which in my case was not needed (as i only needed differences in time). I still have to make a test to check if other methods are faster (such as clock_gettime).

我希望这是你要找的答案的类型。

I hope this is the type of answer you were looking for.

这篇关于是的boost ::了posix_time :: microsec_clock CPU密集型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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