capturing IM processing time

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

capturing IM processing time

Post by fmw42 »

In unix, anyone know how to capture the output from the time function to a string or file?


time convert logo: logo.gif

real 0m1.147s
user 0m0.054s
sys 0m0.069s
zaratol
Posts: 43
Joined: 2010-04-21T08:30:43-07:00
Authentication code: 8675308

Re: capturing IM processing time

Post by zaratol »

to File

( time convert logo: logo.gif ) 2> someReportFile.txt
or: /usr/bin/time -o someReportFile.txt convert logo: logo.gif

time -o won't work and with -o you have a different format of output

to Variable:

temp=$(
{ time convert logo: logo.gif 2>/dev/null
} 2>&1 > /dev/null )

temp=${temp#*real?}
seconds=${temp%?user*}
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: capturing IM processing time

Post by fmw42 »

thanks zaratol. it works. but that is a bit more unix than I understand. Can you explain the use of the parens in

( time convert logo: logo.gif ) 2> someReportFile.txt

and the use of the braces in the following and why they seem to have to be on different lines

temp=$(
{ time convert logo: logo.gif 2>/dev/null
} 2>&1 > /dev/null )

Then I can go do some reading on those concepts.

Thanks

Fred
zaratol
Posts: 43
Joined: 2010-04-21T08:30:43-07:00
Authentication code: 8675308

Re: capturing IM processing time

Post by zaratol »

One concept used here is redirection of output:

http://tldp.org/LDP/abs/html/io-redirection.html

the other is subshells:

http://tldp.org/LDP/abs/html/subshells.html

to be honest, only understand the first example myself, but because i was curious i stumbled on the second example via google 8)
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: capturing IM processing time

Post by anthony »

zaratol wrote:to File

( time convert logo: logo.gif ) 2> someReportFile.txt
or: /usr/bin/time -o someReportFile.txt convert logo: logo.gif
The parenthesis is not needed.

The 2> redirect the error channel (file descriptor number 2) to a file for the given command which is 'time' not 'convert'. However as 'time' executes the given 'convert' command, its errors will be included in the error channel for 'time'.

This also means convert and time errors are merged! however as time only outputs its info AFTER the command is finished the time results will be AFTER any errors from convert.

Alternatives...
time_results=`time convert logo: logo.gif 2>&1`

The 2>&1 here merges the error channel (2) to the normal output channel (1) so that the backticks can capture it.

And here I use a sub-shell to junk any errors from the 'convert' from the output of time.

time_results=`time bash -c 'convert logo: logo.gif 2>/dev/null' 2>&1`
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply