c++ boost计算函数中花费的时间
c++ boost calculate time spent in function
嗨,又有一个boost问题:我需要计算在我的boost线程中的函数中花费的时间:下面是代码:
boost::posix_time::microseconds tes( 12 );
int i = 0;
while( true )
{
boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time( );
myFunction( );
boost::this_thread::sleep( tes );
boost::posix_time::ptime end = boost::posix_time::microsec_clock::local_time( );
boost::posix_time::time_duration elapsed = end - start;
}
所以我尝试了很多次,但是经过的time_duration总是0,我已经添加了12微秒的睡眠功能来测试,所以在最好的方式下,我将有12微秒经过,但仍然是0..我需要告诉线程更新定时器后的时间读取??
谢谢
根据boost文档,local_time
可能无法在Win32系统上实现微秒级分辨率:
ptime microsec_clock: local_time ()
使用亚秒分辨率时钟获取本地时间。在Unix系统上,这是使用GetTimeOfDay实现的。在大多数Win32平台上,它是使用ftime实现的。Win32系统通常无法通过此API实现微秒分辨率。如果更高的分辨率对您的应用程序至关重要,请测试您的平台以查看实现的分辨率。
可能你唯一的选择是使用高分辨率计时器(不便携)
相关文章:
- 使用Boost Interprocess创建托管共享内存需要很长时间
- C++,自使用boost和std::chrono的纪元以来的时间?为什么 Boost 版本慢 10 倍?
- 如何将 time-uuid(存储在 boost uuid 中)转换为时间戳/自纪元以来的时间?
- 为什么 Boost unordered_map 在第一次插入时需要太多时间?
- 将 boost:::chrono::steady_clock::time_point 转换为标准::时间::steady
- 有没有办法使用 Boost 获取区域时间格式?
- 在 Boost 中解析 RFC3339/ISO 8601 时间戳
- boost::asio::d eadline_timer 1ms 滞后一段时间
- 当用绝对时间调用时,为什么BOOST :: TIMED_WAIT块永远
- 使用Boost或STD在特定时区中获取当前的本地时间
- Boost.Spirit X3 编译时间因递归规则而爆炸
- boost::p osix_time:使用夏令时检索时间
- Boost.Test 显示测试持续时间
- 自当地时间上午8点以来,将时间经过的时间与Boost
- BOOST LOCAL_DATE_TIME:如何设置特定时间信息(小时,最小值和SEC)
- 输出boost :: chrono :: system_clock :: time_point作为UTC的本地时间
- boost asio::async_write()花费的时间太长
- 对于C++中的日期/时间库,是否有一种轻量级的Boost替代方案
- 使用Posix时间的Boost线程超时
- 在boost中比较不同时区的时间