Linux 如何仅在脚本完成后获取多个命令的执行时间?
我正在从一个脚本运行大量命令,并测量执行时间(仅其中几个)。我知道如何使用Linux 如何仅在脚本完成后获取多个命令的执行时间?,linux,bash,shell,time,fish,Linux,Bash,Shell,Time,Fish,我正在从一个脚本运行大量命令,并测量执行时间(仅其中几个)。我知道如何使用时间。但我也希望在整个脚本完成后(在shell中或在文件中)一直输出。我该怎么做 编辑: 很抱歉,我应该指定我使用的是Fish shell(不过,我会将bash添加到标记中,以便其他人可以使用答案)。bash 4.2及更高版本有一个模糊的命令,用于将unix时间保存到变量 #!/bin/bash # start time printf -v s_time '%(%s)T' -1 # do stuff sleep 1 s
时间。但我也希望在整个脚本完成后(在shell中或在文件中)一直输出。我该怎么做
编辑:
很抱歉,我应该指定我使用的是Fish shell(不过,我会将bash添加到标记中,以便其他人可以使用答案)。bash 4.2及更高版本有一个模糊的命令,用于将unix时间保存到变量
#!/bin/bash
# start time
printf -v s_time '%(%s)T' -1
# do stuff
sleep 1
sleep 2
sleep 3
# end time
printf -v e_time '%(%s)T' -1
# do more stuff
sleep 4
# print result
echo It took $(( e_time - s_time )) seconds
显示“do stuff”多个命令的运行时
It took 6 seconds
bash4.2和更高版本有一个模糊的命令,用于将unix时间保存到变量
#!/bin/bash
# start time
printf -v s_time '%(%s)T' -1
# do stuff
sleep 1
sleep 2
sleep 3
# end time
printf -v e_time '%(%s)T' -1
# do more stuff
sleep 4
# print result
echo It took $(( e_time - s_time )) seconds
显示“do stuff”多个命令的运行时
It took 6 seconds
选项1:
npm install -g gnomon
./your_script.sh | gnomon
只需尝试以以下方式运行脚本:
time ./your_script.sh
选项2:
npm install -g gnomon
./your_script.sh | gnomon
选项1:
npm install -g gnomon
./your_script.sh | gnomon
只需尝试以以下方式运行脚本:
time ./your_script.sh
选项2:
npm install -g gnomon
./your_script.sh | gnomon
我想您需要将时间
的输出存储到变量。这可能会有帮助:我想您需要将时间
的输出存储到变量。这可能会有帮助:很好。我不知道printf
内置的这个新功能。每天学点东西!美好的我不知道printf
内置的这个新功能。每天学点东西!