use*_*382 11 macos shell time milliseconds
我想知道是否有办法从 Mac OS 上的 shell 脚本获取以毫秒为单位的时间。
我需要它来计算某个查询运行的时间。
现在我只能得到以秒为单位的时间:
Start=`date +%s`
End =`date +%s`
Time=$Start-$End
Run Code Online (Sandbox Code Playgroud)
Die*_*ich 17
您可以使用基准测试工具hyperfine
(https://github.com/sharkdp/hyperfine)。
它比 更复杂time
,默认情况下多次运行命令并给出平均运行时间、偏差、最小值和最大值。
使用简单
\nhyperfine your_command\n
Run Code Online (Sandbox Code Playgroud)\n结果如下所示(hyperfine \'sleep 0.5\' 的结果):
\nbash-3.2$ hyperfine \'sleep 0.5\'\nBenchmark #1: sleep 0.5\n Time (mean \xc2\xb1 \xcf\x83): 505.6 ms \xc2\xb1 1.5 ms [User: 0.8 ms, System: 1.2 ms]\n Range (min \xe2\x80\xa6 max): 503.1 ms \xe2\x80\xa6 508.8 ms 10 runs\n
Run Code Online (Sandbox Code Playgroud)\n有一点需要注意,最小运行次数是 2 ( hyperfine -r 2 \'your command\'
)。
安装
\nHyperfine 可以通过 Homebrew 安装:
\nbrew install hyperfine\n
Run Code Online (Sandbox Code Playgroud)\n有关更多信息,请参阅:https://github.com/sharkdp/hyperfine#on-macos
\n只需使用“时间”命令:
time something
Run Code Online (Sandbox Code Playgroud)
可能是 shell 或命令(查找等)
“真实”时间是您想要的总经过时间,包括毫秒
归档时间: |
|
查看次数: |
10463 次 |
最近记录: |