This question already has an answer here:
这个问题已经有了答案:
- What do 'real', 'user' and 'sys' mean in the output of time(1)? 4 answers
- “real”、“user”和“sys”在时间(1)的输出中是什么意思?4答案
$ time ./Test
real 0m2.906s
user 0m2.887s
sys 0m0.017s
Here is the program code:
这里是程序代码:
#include <iostream>
#include <map>
void func_a() {
std::map<int, int> m;
for (unsigned int i = 0; i < 10000; i++) {
m.insert(std::pair<int, int>(i, i));
}
}
void func_b() {
std::map<int, int> m;
for (unsigned int i = 0; i < 1000000; i++) {
m.insert(std::pair<int, int>(i, i));
}
}
int main() {
func_a();
func_b();
return 0;
}
1 个解决方案
#1
29
If you take a look at the manpage (man time
), it states:
如果你看一下手册(man time),上面写着:
The time command runs the specified program command with the given arguments. When command finishes, time writes a message to standard output giving timing statistics about this program run. These statistics consist of (i) the elapsed real time between invocation and termination, (ii) the user CPU time (the sum of the tms_utime and tms_cutime values in a struct tms as returned by times(2)), and (iii) the system CPU time (the sum of the tms_stime and tms_cstime values in a struct tms as returned by times(2)).
时间命令使用给定的参数运行指定的程序命令。当命令完成时,时间会向标准输出写入一个消息,给出关于这个程序运行的时间统计信息。这些统计数据包括(i)之间的运行实时调用和终止,(ii)用户CPU时间(tms_utime之和和tms_cutime值在struct tms返回时间(2)),和(3)系统CPU时间(tms_stime之和和tms_cstime值在struct tms返回时间(2))。
Basically though, the user
time is how long your program was running on the CPU, and the sys
time was how long your program was waiting for the operating system to perform tasks for it. If you're interested in benchmarking, user + sys
is a good time to use. real
can be affected by other running processes, and is more inconsistent.
基本上,用户时间是你的程序运行在CPU上的时间,而系统时间是你的程序等待操作系统执行任务的时间。如果您对基准测试感兴趣,用户+ sys是一个很好的使用时机。real可能会受到其他正在运行的进程的影响,并且更加不一致。
#1
29
If you take a look at the manpage (man time
), it states:
如果你看一下手册(man time),上面写着:
The time command runs the specified program command with the given arguments. When command finishes, time writes a message to standard output giving timing statistics about this program run. These statistics consist of (i) the elapsed real time between invocation and termination, (ii) the user CPU time (the sum of the tms_utime and tms_cutime values in a struct tms as returned by times(2)), and (iii) the system CPU time (the sum of the tms_stime and tms_cstime values in a struct tms as returned by times(2)).
时间命令使用给定的参数运行指定的程序命令。当命令完成时,时间会向标准输出写入一个消息,给出关于这个程序运行的时间统计信息。这些统计数据包括(i)之间的运行实时调用和终止,(ii)用户CPU时间(tms_utime之和和tms_cutime值在struct tms返回时间(2)),和(3)系统CPU时间(tms_stime之和和tms_cstime值在struct tms返回时间(2))。
Basically though, the user
time is how long your program was running on the CPU, and the sys
time was how long your program was waiting for the operating system to perform tasks for it. If you're interested in benchmarking, user + sys
is a good time to use. real
can be affected by other running processes, and is more inconsistent.
基本上,用户时间是你的程序运行在CPU上的时间,而系统时间是你的程序等待操作系统执行任务的时间。如果您对基准测试感兴趣,用户+ sys是一个很好的使用时机。real可能会受到其他正在运行的进程的影响,并且更加不一致。