Andreas Mohrhard
Andreas Mohrhard

Reputation: 197

Benchmarking programs on Linux

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

Upvotes: 3

Views: 1091

Answers (1)

Antonin Portelli
Antonin Portelli

Reputation: 698

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"

Upvotes: 6

Related Questions