man time is a good start - on Linux you get the GNU time version.
Note: some shells (e.g.,bash(1)) have a built-in time command that provides less functionality than the command described here. To access the real command, you may need to specify its pathname (something like /usr/bin/time).
A call of /usr/bin/time gives a lot of information:
/usr/bin/time ls > /dev/null
0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 3536maxresident)k
0inputs+0outputs (0major+265minor)pagefaults 0swapsThe information can be formatted with a format string (see man time), and we could just output the max. resident memory for example:
/usr/bin/time -f "mem: %M kilobytes" ls > /dev/null
mem: 3520 kilobytesA call of time in bash, the bash builtin, gives us less information but more precise times:
time ls > /dev/null
real 0m0.003s
user 0m0.001s
sys 0m0.001sIt can be formatted like this:
TIMEFORMAT='%lU';time ( ls ) 2>&1 1>/dev/nullThe builtin bash command time gives milisecond precision of execution, and GNU time (usually /usr/bin/time) gives centisecond precision. The times(2) syscall gives times in clocks, and 100 clocks = 1 second (usually), so the precision is like GNU time. What is bash time using so that it is more precise?
Bash time internally uses getrusage() and GNU time uses times().
getrusage() is far more precise because of microsecond resolution.
/usr/bin/timeseems to report too much memory for max. resident size:http://lkml.indiana.edu/hypermail/linux/kernel/1210.0/03883.html