How to know maximum memory usage of a process?

view story

http://unix.stackexchange.com – I have a process, which is quite short-running (about 10 minutes), but memory heavy. I want to know how much memory does the process uses at its peak. I want some way to track it, more efficient than running htop and writing down the memory usage every 20 seconds. Ideally, I would like something like time - some way to write trackmemory command and the command would run and at the end, the memory usage would be shown. However, I will survive manually writing the pid somewhere; I just don't want to watch htop and writing it down. (HowTos)