MULTITIME(1)
π MULTITIME(1) π
okay bestie, welcome to multitime from the General Commands Manual section β it's the little tool that times your commands over multiple runs and then gives you actual stats instead of vibes. π
β¨ NAME β¨
multitime β time command execution over multiple executions. no cap, that's the whole job. π
π¦ SYNOPSIS π¦
multitime [-f liketime | rusage] [-I replstr] [-i stdincmd] [-n numruns]
[-o stdoutcmd] [-q] [-r precmd] [-s sleep] [-v] command
[arg1, ..., argn]
multitime -b batchfile [-f liketime | rusage] [-n numruns] [-s sleep]
[-v]
πΈ DESCRIPTION πΈ
so like, Unix's time(1) utility is a cute lil way of measuring how long a command takes to run. but β and this is the tea β running a command once can hand you straight-up misleading timings. π the process might build a cache on its first execution and then run faster afterwards, other processes might starve your command of CPU or IO time, etc. etc. and it's so common to see people run time(1) a bunch of times and then just pick whichever numbers they feel most comfortable with. which, bestie, inevitably causes problems. π
multitime is, at its heart, a simple lil extension to time(1) that runs command multiple times and then prints the timing means, standard deviations, mins, medians, and maxes after doing so. that gives you a much better understanding of how your command actually performs. π«Ά it also has a bunch of options for advanced uses. for basic uses, you can straight up replace time(1) by using the -n option to say how many times command should be executed. e.g. if we wanna time awk(1):
$ multitime -n 5 awk 'function fib(n) \
{ return n <= 1? 1: fib(n - 1) + fib(n - 2) } BEGIN { fib(30) }'
the full set of options is as follows:
-bbatchfile β execute multiple commands from batchfile. the BATCHFILES section below has the details, iykyk. π-f liketime | rusageβ if it's called astime, the default output style of multitime is POSIX.2 compatible, showing means forreal,user, andsysreadings.-f liketimeforces POSIX.2 compatibility in all cases. otherwise, the default output style is an incompatible extension that shows means, standard deviations, mins, medians, and maxes.-f rusageadditionally shows the entire output of therusagestructure. π-Ireplstr β instances of replstr found in inputcmd, outputcmd, and precmd get replaced with an integer denoting the current execution run number, from1to numruns (both inclusive). π―-istdincmd β before the timing of each execution of command, stdincmd is executed and its output is piped to a temporary file. that temporary file is then used asstdinfor command, so you can make sure every single execution of command sees exactly the input onstdinyou expected. stdincmd is a full shell command which is passed topopen(3). π-lβ same as-f rusage, for compatibility withtime(1). β¨-nnumruns β specify how many times command should be executed. defaults to1. π’-ostdoutcmd β when executing command, its output is piped to a temporary file. after execution has finished, stdoutcmd is then executed, with the temporary file being itsstdin. if stdoutcmd returns an exit code (i.e. non-zero), multitime stops executing. this can be used as a sanity check that command is executing as per expectations. stdoutcmd is a full shell command which is passed topopen(3). this option is mutually exclusive with-q. π«-pβ same as-f liketime, for compatibility withtime(1). π-rprecmd β before each execution of command β and, if it is specified, before stdincmd β precmd is executed by callingsystem(3). this can be used to set the system to a known good state. if precmd returns an exit code (i.e. non-zero), multitime stops executing. π-qβ if specified once,-qsuppresses stdout output; if specified twice,-qqsuppresses both stdout and stderr. this can be useful for programs which produce voluminous output, which can lead to you unintentionally measuring the output speed of the terminal being used, rather than command itself. this option is mutually exclusive with-o. π€«-ssleep β multitime pauses a random length of time between0and sleep seconds between each command execution. particularly for short-running commands, this can smooth out temporary peaks and troughs. if not specified, sleep defaults to3seconds; if set to0, multitime does not sleep at all between executions. π΄-vβ causes verbose output (e.g. which commands are being executed). π£οΈ
heads up bestie: multitime exits immediately if any execution of command fails, returning the failed command's error code. π
π§ BATCHFILES π§
batchfiles are only needed for advanced uses of multitime. one important use is when multitime is being used to compare the performance of multiple commands. the obvious way to do that is to execute multitime for each command and record its output. however β it's possible that one command is unduly affected by issues elsewhere in the machine (e.g. a cron(8) job running in the background), which distorts the comparison. π batchfiles let multiple completely different commands be executed, with each iteration running a random command. assuming numruns is set sufficiently high, batchfiles tend to better spread timing problems over the whole set of commands rather than a single command. π
the format of batchfiles is relatively simple, being more or less a cut-down version of the normal multitime arguments without having to specify multitime itself. each line specifies a command to be executed. each line has the format:
[-I replstr] [-i stdincmd] [-o stdoutcmd] [-q] [-r precmd] command
[arg1, ..., argn]
the -f, -n, -s, and -v options are global and can not be specified in the batch file. π«
π EXAMPLES π
a basic invocation of multitime is as follows:
$ multitime -n 10 awk 'function fib(n) \
{ return n <= 1? 1: fib(n - 1) + fib(n - 2) } BEGIN { fib(30) }'
command will produce its output as normal; multitime will then produce output such as the following on stderr:
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.474 0.001 0.473 0.474 0.477
user 0.456 0.016 0.430 0.460 0.480
sys 0.000 0.000 0.000 0.000 0.010
as an example of more complex uses of multitime, one could time the overall performance of sort(1) on different sequences of random data using -i:
$ multitime -i 'jot -r 1000000 1 100000' -n 10 -q sort
note that each execution of sort(1) will receive different output from jot(1). if you want each execution to receive the same data, use a two-stage sequence with cat(1):
$ jot -r 1000000 1 100000 > file
$ multitime -i 'cat file' -n 10 -q sort
if you are timing sort(1) against pre-defined batches of data (called data1, data2, ..., data10):
$ multitime -I{} -i 'cat data{}' -n 10 -q sort
if you want to cache the output of each execution of command use -o:
$ multitime -I{} -n 3 -o 'cat > file{}' md5 -t
an example batch file bf is as follows:
-i 'jot -r 100000 1 100000' -q sort
md5 -t
and may be invoked thus:
$ multitime -b bf -n 10
π LIMITATIONS π
even though multitime goes out of its way not to colour timings, ultimately the operating system and tasks executing in the system can significantly affect timing measurements. for example, multitime timings include the time to fork(2) a process and execvp(3) a command, which are entirely outside its hands. short-running tasks can be particularly affected by seemingly minor blips in system activity. π
there are methods which can increase the likely accuracy of timing measurements. for example, raising numruns (and, depending on your circumstances, sleep) reduces the likelihood of temporary blips distorting timing measurements. if you're comparing the execution times of multiple commands, the use of batchfiles can spread blips out rather than concentrating them on a single command. increasing the process priority of multitime can decrease the likelihood of other tasks interfering with timings. ultimately, however, there can never be absolute guarantees of accuracy. instead, such methods should be thought of as increasing the likelihood that the numbers returned are indicative of the 'true' measurements. by presenting means and standard deviations, multitime encourages the use of confidence intervals, a statistical technique which encourages this mode of thinking. πβ¨
π AUTHORS π
multitime was written by Laurence Tratt <http://tratt.net/laurie/>. π
and that's the whole page bestie!! π this lil icon shipped from Debian, dated August 31, 2012 β so go forth and time your commands over multiple executions, slay, and remember: means and standard deviations are your besties now. periodt. π β¨π¦
π¦ where this page comes from
- debian bookworm: multitime 1.4-2 Β· MIT
- nixos 26.05: multitime 1.5
- nixpkgs unstable: multitime 1.5
- ubuntu jammy: multitime 1.4-2 Β· MIT
- ubuntu noble: multitime 1.4-2 Β· MIT
- Copyright (C)2012 Laurence Tratt http://tratt.net/laurie/
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms