将返回 CPU 时间提升为 0
Boost returning CPU time of 0
我正在尝试测量C++程序中函数的CPU时间。我正在使用提升库来执行此操作。但是,当我运行程序时,我得到的结果为 0 秒。我是新手,所以如果有人能指出我正确的方向?
如何使此返回成为我可以实际使用的时间,例如 0.00156 或其他什么?
代码:在 main(( 内部
boost::timer::cpu_timer timer;
std::cout << tree1.search("Cork") << std::endl;
//Print CPU TIME
boost::timer::cpu_times elapsed = timer.elapsed();
std::cout << " CPU TIME: " << (elapsed.user + elapsed.system) / 1e9 << " seconds" << std::endl;
您可以使用boost
chrono
;
boost::timer::cpu_timer timer;
std::cout << tree1.search("Cork") << std::endl;
//Print CPU TIME
boost::chrono::duration<double> elapsed = boost::chrono::nanoseconds(timer.elapsed().user);
std::cout << " CPU TIME: " << seconds.count() << "sn" << " seconds" << std::endl;
相关文章:
- 如果返回 -1,时间() 的参数是否被修改?
- 为什么在尝试测量函数返回所需的时间时,我的运行时编号是错误的?
- 保持排序的数据结构,允许log N插入时间,并且可以返回我在log N中查找的元素的索引
- 对于等待以 std::future wait() 返回的函数的 CPU 使用率或检查标志在循环中休眠一段时间哪个更好?
- 为什么时间测量有时会返回重复值(15.625ms 的倍数)?
- 解决PNP在一段时间后返回坏的rvec和tvec
- GetCurrentTime() 不返回正确的时间
- C++ Poco SQL 查询不返回具有'between'和'and'日期时间绑定的结果
- 特征:返回对具有编译时间尺寸检查的矩阵块的引用
- C 将NTP服务器返回的时间转换为字符串
- C 函数在编译时间返回类型
- 如何从一段时间返回继续
- system_clock返回负时间 C++
- 将返回 CPU 时间提升为 0
- 长时间返回错误的数据
- vector::size() 如何在常量时间内返回向量的大小
- C++/如何返回最佳时间结果
- 在添加或减少天数后提升日期时间返回值
- c++系统时间返回相同的错误值
- 根据当前时间返回下一秒