问题描述
对于一项分配,我们需要使用不同的优化和参数来对我们的实现进行基准测试.有没有一种可行的方法可以用不同的参数对Linux命令行(我知道时间)上的小程序进行基准测试,从而为我提供时间数据为CSV或类似的数据?输出可能是这样的:
for an assignment we need to benchmark our implementations with different optimizations and parameters. Is there a feasible way of benchmarking little programs on the linux command line (I know of time) with different parameters which gives me the time data as CSV or something similiar? Output could be something like:
Implementation Time
A 23s
B with -O3 2Threads 15s
B with -O3 4Threads 10s
我很确定我已经在一些教授的幻灯片上看到过类似的东西,但是我不记得是谁或什么时候...
I'm pretty sure that I've seen something like that on some professors slides but I cant remember who or when it was...
推荐答案
为什么不在bash
脚本中使用time
命令,例如:
Why not using time
command inside a bash
script, something like :
#!/bin/bash
NPROG=`cat proglist | wc -l`
for i in `seq 1 ${NPROG}`
do
PROG=`sed -n "${i}p" proglist`
ARG=`sed -n "${i}p" arglist`
TIME=`{ time ${PROG} ${ARG}; } 2>&1 | grep real | awk '{print $2}'`
echo "${TIME} ${PROG} ${ARG}"
done
其中proglist
是一个文本文件,其中包含要执行的程序
where proglist
is a text file containing the programs to execute
A
B
B
和arglist
是一个包含参数的文本文件,例如:
and arglist
is a text file containing the arguments, something like :
-a 1 -b 2
-f "foo"
-f "bar"
脚本的输出将类似于:
0m32.000s A -a 1 -b 2
1m12.000s B -f "foo"
5m38.000s B -f "bar"
这篇关于Linux上的基准测试程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!