【发布时间】:2017-10-01 13:42:37
【问题描述】:
我用它来测量 C++ 中的执行时间:
struct timeval t1, t2;
gettimeofday(&t1, NULL);
gettimeofday(&t2, NULL);
int milliSeconds = (t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec)/1000;
但我还想测量 CPU / 内存消耗。我该怎么做?
【问题讨论】:
-
检查
getrusage(),最好知道您的特定过程花费了多少时间而不是总实时时间。 -
您需要指定目标操作系统是什么,您想知道什么样的 CPU 使用率?周期数?可运行的时间?时钟时间?运行时间?使用百分比?
-
不确定它是否是您想要的,但如果您正在寻找微基准库,请尝试 Google 提供的这个:github.com/google/benchmark。它测量每次迭代的 CPU 时间以及其他内容。
-
@LiranFunaro 对不起,我想要百分比的使用率,如果可能的话,运行时间。你能帮帮我吗?
-
@AlexisWilke 非常感谢!留着记忆就好了!
标签: c++ memory time cpu cpu-usage