我正在使用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