在linux机器上,time命令可以记录程序运行时间。
在控制台直接输入 time <command>, 会输出三个值,real, user, sys. 关于这三个值的含义在很多博客中都有说明。
在后台运行time 命令,输出是user, system, elapsed. 单位也和之前的不一样。
GNU VERSION
Below a description of the GNU 1.7 version of time. Disregarding the name of the utility, GNU makes it output lots of useful information, not only about time used, but also on other resources like memory, I/O and IPC calls (where available). The output is formatted using a format string that can be specified using the -f option or the TIME environment variable. The default format string is: %Uuser %Ssystem %Eelapsed %PCPU (%Xtext+%Ddata %Mmax)k %Iinputs+%Ooutputs (%Fmajor+%Rminor)pagefaults %Wswaps When the -p option is given, the (portable) output format is used: real %e user %U sys %S The format string The format is interpreted in the usual printf-like way. Ordinary characters are directly copied, tab, newline and backslash are escaped using \t, \n and \\, a percent sign is represented by %%, and otherwise % indicates a conversion. The program time will always add a trailing newline itself. The conversions follow. All of those used by tcsh(1) are supported. Time %E Elapsed real time (in [hours:]minutes:seconds). %e (Not in tcsh(1).) Elapsed real time (in seconds). %S Total number of CPU-seconds that the process spent in kernel mode. %U Total number of CPU-seconds that the process spent in user mode. %P Percentage of the CPU that this job got, computed as (%U + %S) / %E. Memory %M Maximum resident set size of the process during its lifetime, in Kbytes. %t (Not in tcsh(1).) Average resident set size of the process, in Kbytes. %K Average total (data+stack+text) memory use of the process, in Kbytes. %D Average size of the process's unshared data area, in Kbytes. %p (Not in tcsh(1).) Average size of the process's unshared stack space, in Kbytes. %X Average size of the process's shared text space, in Kbytes. %Z (Not in tcsh(1).) System's page size, in bytes. This is a per-system constant, but varies between systems. %F Number of major page faults that occurred while the process was running. These are faults where the page has to be read in from disk. %R Number of minor, or recoverable, page faults. These are faults for pages that are not valid but which have not yet been claimed by other virtual pages. Thus the data in the page is still valid but the system tables must be updated. %W Number of times the process was swapped out of main memory. %c Number of times the process was context-switched involuntarily (because the time slice expired). %w Number of waits: times that the program was context-switched voluntarily, for instance while waiting for an I/O operation to complete. I/O %I Number of filesystem inputs by the process. %O Number of filesystem outputs by the process. %r Number of socket messages received by the process. %s Number of socket messages sent by the process. %k Number of signals delivered to the process. %C (Not in tcsh(1).) Name and command-line arguments of the com‐ mand being timed. %x (Not in tcsh(1).) Exit status of the command.