Bash Scripting - Timing functions

jdawgaz at cox.net jdawgaz at cox.net
Tue May 20 14:53:05 MST 2008


just put a line like this before and after the function call
for the number of seconds difference

if you need something shorter timed than a second, I do '%s%N' instead.
(see date command: i.e. man date)

BEFORE=$(date +'%s')
funct
AFTER=$(date +'%s')
TOTAL=$(( $AFTER-$BEFORE ))
echo $TOTAL

---- David Bendit <DarkElf109 at ibendit.com> wrote: 
> Hey there,
> 
> I'm relatively unskilled at shell scripting, and I can't quite figure 
> out how to time individual functions, rather than entire commands. Is 
> there any way to do this? /usr/bin/time or bash's time reserved word 
> both work, as long as I can time a single function.
> 
> Thanks,
> David Bendit
> 



More information about the PLUG-discuss mailing list