Hi, 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.
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.
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
#!/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.
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.