的运行时间,我想运行它,比如说后报告的平均运行时间脚本(使用time command计算),ñ倍。有没有一个简单的bash
命令,脚本或系统实用程序,我不知道,这将允许我这样做?平均在多个运行
Q
平均在多个运行
4
A
回答
0
没有一个单一的命令可以做到这一点。你可以做的是将每次运行的时间附加到一个文件中,然后计算这些数字的平均值。
11
这是一个有趣的问题so I took a few minute and wrote a script for it。以下是指示灯脚本的版本,该脚本输入的文件具有运行time
命令的输出。 The full script有更多的选项,并直接接受命令直接运行平均值。
代码:
#!/bin/bash
# calculate the mean average of wall clock time from multiple /usr/bin/time results.
file=${1}
cnt=0
if [ ${#file} -lt 1 ]; then
echo "you must specify a file containing output of /usr/bin/time results"
exit 1
elif [ ${#file} -gt 1 ]; then
samples=(`grep --color=never real ${file} | awk '{print $2}' | cut -dm -f2 | cut -ds -f1`)
for sample in `grep --color=never real ${file} | awk '{print $2}' | cut -dm -f2 | cut -ds -f1`; do
cnt=$(echo ${cnt}+${sample} | bc -l)
done
# Calculate the 'Mean' average (sum/samples).
mean_avg=$(echo ${cnt}/${#samples[@]} | bc -l)
mean_avg=$(echo ${mean_avg} | cut -b1-6)
printf "\tSamples:\t%s \n\tMean Avg:\t%s\n\n" ${#samples[@]} ${mean_avg}
fi
例(在这里我命名脚本timeit.sh
和chmod 775 timeit.sh
和chown jon timeit.sh
*):
[ 09:22 [email protected] ~ ]$ /usr/bin/time -a -o times.log -p sleep 3
[ 09:23 [email protected] ~ ]$ /usr/bin/time -a -o times.log -p sleep 1
[ 09:23 [email protected] ~ ]$ /usr/bin/time -a -o times.log -p sleep 2
[ 09:23 [email protected] ~ ]$ /usr/bin/time -a -o times.log -p sleep 2
[ 09:23 [email protected] ~ ]$ /usr/bin/time -a -o times.log -p sleep 7
[ 09:23 [email protected] ~ ]$ /usr/bin/time -a -o times.log -p sleep 0.5
[ 09:23 [email protected] ~ ]$ ./timeit.sh times.log
Samples: 6
Mean Avg: 2.5833
[ 09:23 [email protected]zbox.com ~ ]$ cat times.log
real 3.00
user 0.00
sys 0.00
real 1.00
user 0.00
sys 0.00
real 2.00
user 0.00
sys 0.00
real 2.00
user 0.00
sys 0.00
real 7.00
user 0.00
sys 0.00
real 0.50
user 0.00
sys 0.00
* chown
心不是在这里有必要,但我忍不住它! :)
语法
time [option...] command [arg...]
选项
-o FILE --output=FILE
写的资源使用统计文件。
-a --append
追加资源使用信息的输出文件覆盖它,而不是 。
-o FILE --output=FILE
将资源使用统计信息写入FILE。默认情况下,这个 覆盖该文件,销毁该文件的以前的内容。
-p --portability
使用POSIX格式。
+0
我真的很喜欢这个。 – mathiasrw
1
我在这里问的是类似的东西:Average Execution Time。建议使用Dumbbench,这是一个Perl脚本,它可以多次运行该软件并打印出一些统计数据。
相关问题
- 1. 平均多个UIImages
- 2. 计算运行平均值
- 3. 12个月13周平均运行
- 4. 平均多行中访问
- 5. PHP运行多个数组值差异的平均值
- 6. 运动平均
- 7. 在MATLAB中计算运行平均数
- 8. 在SSL上运行平均值堆栈
- 9. Bash,如何获得多个平均执行时间的平均执行时间?
- 10. 多个滑块和平均
- 11. DAX:平均多个%列
- 12. 平均多列
- 13. 猪平行平均
- 14. 平均多重均线
- 15. Rethinkdb在一个查询中执行多个平均值
- 16. MySql多种平均水平
- 17. 平均行
- 18. 平均n行
- 19. 多个表中的平均值的平均值
- 20. 计算多个平均值的平均值
- 21. 运行调和平均算法?
- 22. 制造连续运行数平均
- 23. 多列平均值
- 24. 如何显示张量板上多次运行的平均值
- 25. 读值平均行
- 26. MYSQL平均N行
- 27. 对一个方法的多个结果进行平均?
- 28. 将多个csv文件平均放入r中的1个平均文件中
- 29. 平均在一个查询
- 30. 计算多个列的平均值
http://superuser.com/questions/603897/how-to-measure-average-execution-time-of-a-script –