Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am timeing some of my commands. Now to average the measures, I'd like to run and time my commands a specified number of times, and get the results with a calculated mean and standard deviation. The result would be like:

avgtime -n 100 my_command

real    0m5.388s stdev 0m0.068s
user    0m5.380s stdev 0m0.067s
sys     0m0.004s stdev 0m0.000s

Is there a UNIX tool for this? Does GNU/Linux have one?

share|improve this question

It's not exactly a UNIX or GNU/Linux tool, but you could quite comfortably use the R software environment for statistical computing for this. (I cannot find anything more specific for your task, though.)

Edit How could I doubt it, there of course is a benchmark package for R: rbenchmark. It apparently wraps system.time() which you could also just use directly. Or have a look at this, a simple stopwatch function pair. Also see "Executing a system command" @Rosetta Code (or don't, it's system("command").)

Edit2 I just saw this question, "Measuring time within a script" in the right "Related" column, this could be used, too, i.e. take time, do for-loop (N times), take time again, calculate timespan, divide by N. (Even easier, try time ( for-loop ), parse its output, divide by N).

share|improve this answer

Option 1 - sqlite:

create simple table with command and time columns, and view with proper aggregation calculations. After timing, add a row to the table.

Advantages: simpler to define a table compared to solution 2.

Disadvantages: you need (do you?) care about data retention.

Option 2 - rrdtool:

Define rrd data base file, data definition and aggregation functions. After timing, feed the database with rrdtool update ....

Advantages: you can easily generate graphs with rrdtool graph .... No data retention issue (round robin database).

Disadvantages: bit harder to define rrd database compared to simple SQL table/view

share|improve this answer

You can to try use the timeit module, available in any system with Python:

$ python -m timeit "__import__('os').system('my comand here')"
10 loops, best of 3: 591 msec per loop
share|improve this answer
using os.system(), causes the overhead of calling/creating a shell with each command. Probably better use subprocess.call() – Anthon Apr 10 '14 at 15:33
true, but would be likely constant-ish anyway – bhdnx Apr 10 '14 at 19:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.