WTF time? Give me options!
I’m looking at the computational cost of computing various hashes. Naturally, I want to collect run time statistics on each hash command and collect this metric several thousand times.
The natural choice is to go with time, but I need to use time’s format option to output a CSV output. Sounds easy:
brooks@saosin:~$ time -f %e,%S,%U md5sum .viminfo
bash: -f: command not found
real 0m0.002s
user 0m0.000s
sys 0m0.002s
WTF? -f is an option, not a command! Come to find out, Bash has its own built-in time command which doesn’t have the same options as the GNU time command! So you’ll need to use the full path to the GNU utility. If you don’t know it, use which:
brooks@saosin:~$ which time
/usr/bin/time
Now, let’s try this again:
brooks@saosin:~$ /usr/bin/time -f %e,%S,%U md5sum .viminfo
0cc07f508925f94b18f50166576b83c7 .viminfo
0.00,0.00,0.00
Better!
You can also use -a -o filename to specify where to put that csv output across multiple runs.
About the author
Brooks Garrett is a dedicated technologist who specializes in information security. Brooks has spent over 10 years implementing security programs for both the public and private sector including some of the biggest names in the Fortune 500. When he's not managing risk in the corporate environment you can find him at the local firestation where he is a volunteer firefighter.