Benchmarking programs on Linux

2019-07-07 12:30发布

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...

1条回答
男人必须洒脱
2楼-- · 2019-07-07 13:27

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

where proglist is a text file containing the programs to execute

A
B
B

and arglist is a text file containing the arguments, something like :

-a 1 -b 2
-f "foo"
-f "bar"

The output of the script will look-like :

 0m32.000s A -a 1 -b 2
 1m12.000s B -f "foo"
 5m38.000s B -f "bar"
查看更多
登录 后发表回答