shell scripting

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

Post Reply
ngungo
Forum Commoner
Posts: 75
Joined: Thu Jun 08, 2006 10:45 pm

shell scripting

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

you might want to look into 'time' command.
ngungo
Forum Commoner
Posts: 75
Joined: Thu Jun 08, 2006 10:45 pm

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
ngungo
Forum Commoner
Posts: 75
Joined: Thu Jun 08, 2006 10:45 pm

Post 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.
Post Reply