Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Average execution time

Tags:

c

bash

profiling

is there any nice GNU way how to measure average (worst case, best case) execution time of some command line program? I have image filter, unspecified amount of pictures, filtering them using for-loop in bash. So far I am using time, but I can't find a way how to get some statistics.

like image 549
Adam Trhon Avatar asked Sep 21 '10 21:09

Adam Trhon


4 Answers

You can send the output of time to some file, and then "work" that file

echo "some info" >> timefile.txt
time ( ./yourprog parm1 parm2 ) 2>> timefile.txt
like image 128
pmg Avatar answered Nov 20 '22 20:11

pmg


There's an interesting Perl program called dumbbench that's essentially a wrapper around the time command. It runs your program a number of times, throws away outliers, then calculates some statistics.

The author has a couple of articles (here and here) outlining a) why benchmarking sucks, and b) what kind of pretty graphs you can make to make your benchmarking numbers suck a little less.

like image 21
CanSpice Avatar answered Nov 20 '22 20:11

CanSpice


You're on the right track with time. It's what I use to preform small code execution analyses.

I then use python to collect the statistics by reading the output of time. In order to increase accuracy, I typically do the trial 10 - 1000 times, depending on how long each process takes.

I'm not familiar with any pre-installed GNU application that does this sort of analysis.

like image 2
Sean Avatar answered Nov 20 '22 20:11

Sean


#!/bin/bash
for i in {1..100}
do
  env time --append -o time_output.txt   ./test_program --arguments-to-test-program
done
exit

If you find that the {1..100} syntax doesn't work for you then you should have a look at the seq command.

I used the env time to execute the time program rather than the shell's built in command, which does not take all of the arguments that the time program takes. The time program also takes other arguments to alter the format of it's output, which you will probably want to use to make the data easier to process by another program. The -p (--portability) argument makes it output in the POSIX format (like BASH's builtin time does), but using the -f option you can get more control. man 1 time for more info.

After you have gathered your data a simple perl or python script can easily parse and analyze your timing data.

like image 2
nategoose Avatar answered Nov 20 '22 18:11

nategoose