有没有办法知道执行一个命令需要多少个滴答/周期?

有没有办法知道执行一个命令需要多少个滴答/周期?

有没有办法知道在 Linux 服务器上执行给定命令需要多少个滴答/周期?

我正在尝试执行一个命令,我想知道该命令的执行速度。这个时间取决于 CPU 速度、硬件还是其他因素?

答案1

您可以使用该time命令。其最简单的形式是:

time [some command]

给出:

real    0m0.103s
user    0m0.004s
sys     0m0.028s

还可以得到更完整的输出:

/usr/bin/time -v [some command]

Command exited with non-zero status 1                                                                                                     
        Command being timed: "find ."                                                                                                     
        User time (seconds): 0.00                                                                                                         
        System time (seconds): 0.01                                                                                                       
        Percent of CPU this job got: 84%                                                                                                  
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.01                                                                              
        Average shared text size (kbytes): 0                                                                                              
        Average unshared data size (kbytes): 0                                                                                            
        Average stack size (kbytes): 0                                                                                                    
        Average total size (kbytes): 0                                                                                                    
        Maximum resident set size (kbytes): 2980
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 142
        Voluntary context switches: 11
        Involuntary context switches: 0
        Swaps: 0
        File system inputs: 80
        File system outputs: 0
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 1

(使用 bash 时,必须使用完整路径以避免运行内置time命令)

输出中的每个项目都会对执行时间产生影响。

相关内容