我正在使用Boost.Unit编写单元测试,并且我正在测试的代码在部分单元测试期间不得超过单个CPU的50%。我怎么能从源代码中做出这个断言?Boost C++库:%处理器使用情况下的单元测试声明
0
A
回答
1
使用的时代呼唤 - 根据手册页:
名称 时间 - 获取进程倍
概要 的#include <SYS/times.h>
clock_t times(struct tms *buf);
描述 times()将当前进程时间存储在buf指向的struct tms中。结构 tms定义如下:
struct tms {
clock_t tms_utime; /* user time */
clock_t tms_stime; /* system time */
clock_t tms_cutime; /* user time of children */
clock_t tms_cstime; /* system time of children */
};
The tms_utime field contains the CPU time spent executing instructions of the calling
process. The tms_stime field contains the CPU time spent in the system while executing
tasks on behalf of the calling process. The tms_cutime field contains the sum of the
tms_utime and tms_cutime values for all waited-for terminated children. The tms_cstime
field contains the sum of the tms_stime and tms_cstime values for all waited-for terminated
children.
0
我会用GetProcessTimes函数,如果你在Windows环境下编程。该函数返回进程使用的内核和用户时间。在需要开始时间然后进行最终测试之前,您需要调用它。
看看它是否超过挂钟时间的50%。
时间为FILETIME格式。此格式旨在支持程序支持不同的整数格式,因此请选择正确的格式。
相关问题
- 1. Boost C++库:单元测试在死锁上的声明
- 2. Oracle:处理空的情况声明
- 3. 未声明语言理想情况下
- 4. 如何在不使用库的情况下进行单元测试?
- 5. 处理空的情况下
- 6. 如何在这种情况下应用单元测试?
- 7. qt单元测试QTreeWidgetItem尚未声明
- 8. Python单元测试声明错误
- 9. 与Shouldly声明单元测试失败
- 10. Python单元测试条件声明
- 11. 或在开关/情况下的声明?
- 12. 选择的情况下,如果声明?
- 13. 传球$事件进行单元测试的情况下,摩卡
- 14. 如何在没有静态测试数据库的情况下使DAO类的单元测试更加脆弱?
- 15. 简单的选项处理使用Boost库(C++)
- 16. 如何在不使用存储库模式的情况下单元测试ASP.NET MVC控制器
- 17. C#如何在没有实现的情况下单元测试接口方法
- 18. 在什么情况下应该避免单元测试?
- 19. 在单元测试情况下检查DefaultHttpContext正文
- 20. 如何在一个特定的情况下在单元测试的开关情况下调用函数?
- 21. 如果声明的情况
- 22. 使用“朋友”声明进行单元测试。馊主意?
- 23. 在不改变类声明的情况下使用MSGPACK_DEFINE
- 24. 如何测试回拨函数? (C++ Boost单元测试)
- 25. 属性跳过声明单元测试C#
- 26. 使用boost C++单元测试套件测试非致命错误消息
- 27. C++:如何在不定义的情况下声明非函数?
- 28. 单元测试的IOError异常处理
- 29. SQL服务器的选择的情况下在声明中
- 30. 声纳C单元测试框架
不幸的是我在linux上 – 2010-09-25 03:22:55