Page 1 of 1

shell scripting

Posted: Sat Oct 27, 2007 10:46 am
by ngungo
I am sure there is better way to do this benchmarking. Thanks in advance for any input!

Code: Select all

#!/bin/sh
# Task benchmarking in seconds
h=`date "+%H"`
h=`expr $h \* 60`
m=`date "+%M"`
m=`expr $h + $m`
m=`expr $m \* 60`
s=`date "+%S"`
s=`expr $m + $s`
# Do the task that needs benchmark
h=`date "+%H"`
h=`expr $h \* 60`
m=`date "+%M"`
m=`expr $h + $m`
m=`expr $m \* 60`
s1=`date "+%S"`
s1=`expr $m + $s1`
s=`expr $s1 - $s`
echo $s

Posted: Sat Oct 27, 2007 6:57 pm
by Weirdan
you might want to look into 'time' command.

Posted: Sat Oct 27, 2007 7:30 pm
by ngungo
Yes, I looked at that but somehow I did not quite understand. It comes back with real, user and sys figures. Would you care to explain? Thanks.

Posted: Sat Oct 27, 2007 7:39 pm
by Weirdan
It could display resources taken by a command (that's what you see) or time spent executing the command, like this:

Code: Select all

time -f "%e" yourcommand
PS. 'man time' would have revealed you this information without the unneeded round-trip to the forum.

Posted: Sat Oct 27, 2007 8:58 pm
by ngungo
The -f "%e" gave error. I looked into the "man time", it does not have that option. Anyway, is there way to extract that real figure only by using, for example, grep, sed or something. Obviously I am not versed with shell scripting.