【发布时间】:2023-12-15 18:21:01
【问题描述】:
致那些将我的问题标记为已回答/重复的人:给定链接中的那些解决方案无法计算 Linux 中多线程程序中的 CPU 时间。
我正在使用以下代码来查找我的代码的执行时间。它在我的 Windows 10 机器上完美运行,但在 Linux 上,我得到不正确的执行时间(例如,实际执行时间不到 2 秒,但代码打印 10 秒)。我已经尝试过 GCC 和 Intel 编译器,但仍然有同样的问题。知道有什么问题吗?感谢您的时间和帮助。
clock_t begin;
clock_t end;
double time_spent;
begin = clock();
// run some calculations //
end = clock();
time_spent = ((double)(end - begin)) / CLOCKS_PER_SEC;
printf("Elapsed: %.12f \n\n", time_spent);
【问题讨论】:
-
Linux
timecommand 在原始程序上试用它会给你什么? -
请在您的问题中提供一些minimal reproducible example。这也缺少
linux标签