We at Johnny’s Software Lab LLC are experts in performance. If performance is in any way concern in your software project, feel free to contact us.
Linux comes with a built-in utility called time that you can use to measure your program’s runtime. However, this utility is really basic. This is where multitime comes into play. The utility is available in the repositories of (probably) all Linux distributions.
Measure time
Multitime measures your program’s runtime, but not only that. Its magic is about being able to execute the same command several times, and getting information about average runtime, standard deviation, minimum and maximum. Here is an example of running a command ten times and getting average runtimes with multitime:
$ multitime -n 10 ./my_command --arg1 val1 --arg2 val2
...
===> multitime results
1: ./my_command --arg1 val1 --arg2 val2
Mean Std.Dev. Min Median Max
real 48.908 1.415 47.082 48.751 50.861
user 43.931 1.186 42.359 43.812 45.594
sys 4.652 0.210 4.375 4.594 5.000
Multitime measures average runtime (mean), standard deviation (Std.Dev.), minimum, median and maximum values. It also measures the overall spent time (real), how much time it spent doing useful work (user) and how much time it spent waiting for a service from the operating system (sys).
Like what you are reading? Follow us on LinkedIn , Twitter or Mastodon and get notified as soon as new content becomes available.
Need help with software performance? Contact us!
Measure resource usage
Another great feature of this tool is that it can measure resource usage. Here is an example:
$ multitime -f rusage -n 5 ./my_command --arg1 val1 --arg2 val2
...
===> multitime results
1: ./my_command --arg1 val1 --arg2 val2
Mean Std.Dev. Min Median Max
real 54.327 5.719 49.561 52.084 65.580
user 48.650 4.592 44.812 46.891 57.688
sys 5.150 0.309 4.641 5.156 5.531
maxrss 4820324 179 4820120 4820276 4820576
minflt 1209712 46 1209661 1209698 1209778
majflt 0 0 0 0 0
nswap 0 0 0 0 0
inblock 0 0 0 0 0
oublock 0 0 0 0 0
msgsnd 0 0 0 0 0
msgrcv 0 0 0 0 0
nsignals 0 0 0 0 0
nvcsw 0 0 0 0 0
nivcsw 0 0 0 0 0
Apart from measuring the runtimes, switch -f rusage
also measures the resource usage and other parameters of the execution. It displays mean value, standard deviation etc, in the same way it displays those parameters for runtimes. The names of the parameters are somewhat cryptic, but they correspond to the names returned by getrusage() call on Linux and you can look them up online1.
Additional Options
Multitime offers a few additional options that can be useful from occasionally.
- It can silence the program’s output because programs that print out too much data can be slow because of the limit in terminal’s output speed.
- It can call the same command several times with different parameters.
- It can pass a customized standard input to the command.
- Sleep between repeating the command.
Final Words
I like multitime. Ever since I discover it, I use it to measure and statistically process my programs’ runtimes. It is simple to grasp and use for everyone, but if you are a performance engineer, multitime will surely become an indispensable part of your toolbox.
- In above case
maxrss
stands for maximum resident set size, which tells you how much memory your system has requested from the operating system (in kB). This is a peak value, meeaning your operating system needs to have at least this amount to run the program without paging. Parameterminflt
stands for minor faults. This tells you the how many times did your program access a memory page which is not mapped, but easily available (meaning that the OS didn’t have to go to read it from the hard drive) [↩]