Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 580
Andreas Mohrhard Avatar asked Aug 06 '26 00:08

Andreas Mohrhard


1 Answers

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"
like image 154
Antonin Portelli Avatar answered Aug 07 '26 12:08

Antonin Portelli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!