TehOne
October 24, 2009, 2:55pm
1
Hello,
I'm running a bash script and I'd like to get more accurate a runtime information then now.
So far I've been using this method:
STARTM=`date -u "+%s"`
.........
*script function....
.........
STOPM=`date -u "+%s"`
RUNTIMEM=`expr $STOPM - $STARTM`
if (($RUNTIMEM>59)); then
TTIMEM=`printf "%dm%ds\n" $((RUNTIMEM/60%60)) $((RUNTIMEM%60))`
else
TTIMEM=`printf "%ds\n" $((RUNTIMEM))`
fi
echo "Executing "script function" took: $TTIMEM"
However the script often runs under one second, so the result is 0s.
I'd like it display a more accurate runtime, best 0.015s or 1.123s and so on...
Scott
October 24, 2009, 3:10pm
2
Hi.
You could try using "time":
time {
........
........
........
}
TehOne
October 24, 2009, 3:54pm
3
Thanks but that's not an option... I do not really echo the $TTIMEM var... that was just an example... I pass it to another script... and then my script goes on and does different stuff...
---------- Post updated at 11:54 AM ---------- Previous update was at 11:13 AM ----------
please delete this theard
Would this work perhaps (using GNU date)?:
#!/bin/ksh
res1=$(date +%s.%N)
sleep 1
res2=$(date +%s.%N)
echo "Start time: $res1"
echo "Stop time: $res2"
echo "Elapsed: $(( res2 - res1 ))"
$> ./test2
Start time: 1256415694.189522104
Stop time: 1256415695.193247576
Elapsed: 1.00372547202277929