If you truly don't need stdout or stderr from the program being timed, this is a fine way to do this and should be as efficient as any other method.
Eddie
2009-06-12 01:21:13
If you truly don't need stdout or stderr from the program being timed, this is a fine way to do this and should be as efficient as any other method.
the only change I would make is
var=$(time (mycommand &> /dev/null) 2>&1)
the $() command syntax if you shell supports it is superior for two reasons.
no need to escape backslashes and you can nest commands without escaping backticks.
see here for a description of the differences: Bash Command Substition
Only the mirror, because the primary seems to be down at the moment:
http://bash-hackers.org/wiki/doku.php/mirroring/bashfaq/032
From Greg's BashFAQ
thanks! however, though it worked for me with linux,
$ TIMEFORMAT="MYTIME %3R"
$ time ./file_$ echo $TIME
MYTIME 0.016
$ TIME=`time ( ./file_tiny foo &> /dev/null ) 2>&1`
$ echo $TIME
MYTIME 0.016
$
not so with cygwin:
$ TIMEFORMAT="MYTIME %3R"
$ time ./file_$ echo $TIME
MYTIME 0.016
$ TIME=`time ( ./file_tiny foo &> /dev/null ) 2>&1`
$ echo $TIME
$
thoughts? (besides "don't use cygwin" :-P it's too obvious.)