gpt4 book ai didi

c++ - boost C++ 库 : Unit Test Assertion on % Processor Usage

转载 作者:太空宇宙 更新时间:2023-11-04 11:40:36 24 4
gpt4 key购买 nike

我正在使用 Boost.Unit 编写单元测试,在单元测试的一部分中,我正在测试的代码不得超过单个 CPU 的 50%。我如何从源代码中做出这个断言?

最佳答案

使用时间调用 - 根据手册页:

姓名 times - 获取处理时间

大纲 #include

   clock_t times(struct tms *buf);

描述 times() 将当前进程时间存储在 buf 指向的结构 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.

关于c++ - boost C++ 库 : Unit Test Assertion on % Processor Usage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3792303/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com