multitime
Overview
Unix'stime utility is a simple and often effective way of measuring how
long a command takes to run (wall time). Unfortunately, running a command once can give misleading timings: the process may create a cache on its first execution, running faster subsequently; other processes may cause the command to be starved of CPU or IO time; etc. It is common to see people run
time several
times and take whichever values they feel most comfortable with. Inevitably,
this causes problems.
multitime is, in essence, a simple extension to time which runs a command multiple times and prints the timing means, standard deviations, mins, medians, and maxes having done so. This can give a much better understanding of the command's performance.
$ multitime -n 5 awk "function fib(n) \
{ return n <= 1 ? 1 : fib(n - 1) + fib(n - 2) } BEGIN { fib(30) }"
===> multitime results
1: awk "function fib(n) \
{ return n <= 1 ? 1 : fib(n - 1) + fib(n - 2) } BEGIN { fib(30) }"
Mean Std.Dev. Min Median Max
real 0.603 0.006 0.599 0.600 0.615
user 0.556 0.038 0.490 0.570 0.600
sys 0.000 0.000 0.000 0.000 0.000
multitime also allows you to manipulate the
stdin and stdout of each execution of a command,
allowing fine-grained control of a command. For example, using
jot to generate random data, we can compare the performance of
sort (lexical sort) and sort -n (numeric sort):
$ multitime -i "jot -r 1000000 1 100000" -q -n 10 sort
===> multitime results
1: sort
Mean Std.Dev. Min Median Max
real 0.387 0.012 0.372 0.381 0.407
user 0.283 0.035 0.220 0.290 0.330
sys 0.049 0.015 0.020 0.050 0.070
$ multitime -i "jot -r 1000000 1 100000" -q -n 10 sort -n
===> multitime results
1: sort -n
Mean Std.Dev. Min Median Max
real 0.488 0.012 0.473 0.484 0.505
user 0.384 0.025 0.340 0.390 0.420
sys 0.072 0.015 0.050 0.070 0.100
Should you use multitime?
If you want to do any of the following, then multitime is worth considering:- You want to run a command several times to understand how its timings naturally vary.
- You want to run a command several times so that temporary blips in system activity do not distort the timings.
- You need different executions of a command being timed to have different inputs / outputs.
- You want to compare the timing of multiple commands (e.g. for benchmarking purposes).
multitime can also be used as a drop-in replacement for the POSiX
time command: when invoked as time (e.g. via a
symlink), multitime behaves as time. For most
users, therefore, multitime can safely replace the
time binary, even if you don't make use of its advanced features.
Download and docs
Download the latest release (includes installation instructions)FAQ
Man page
Related programs