Runtime informations - bash script

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Runtime informations - bash script
# 1  
Old 10-24-2009
Question Runtime informations - bash script


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"`
if (($RUNTIMEM>59)); then
TTIMEM=`printf "%dm%ds\n" $((RUNTIMEM/60%60)) $((RUNTIMEM%60))`
TTIMEM=`printf "%ds\n" $((RUNTIMEM))`

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

Last edited by TehOne; 10-24-2009 at 05:09 PM..
# 2  
Old 10-24-2009

You could try using "time":

time {

# 3  
Old 10-24-2009
Originally Posted by scottn

You could try using "time":

time {

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
# 4  
Old 10-24-2009
Would this work perhaps (using GNU date)?:
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

Last edited by Scrutinizer; 10-24-2009 at 09:29 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash Scripting: Adding runtime in a progress bar

I have the following code that generates a progress bar and want to add the current execution time after the percentage value. The current execution time is stored in the variable `runtm` I am having a problem on how to add `runtm` in the last `printf` or after it. i=0; j=0 ... (3 Replies)
Discussion started by: kristinu
3 Replies

2. UNIX for Beginners Questions & Answers

Bash array variables are changed in loop runtime

I am trying to check whether particular host and port are responding or not. I am using below script to check. but node_port array that i am using in loop is getting replaced with previous iteration value. Script and output is given. Please help me to understanding why node_port values are... (5 Replies)
Discussion started by: tmalik79
5 Replies

3. Shell Programming and Scripting

Shell script to create runtime variables based on the number of parameters passed in the script

Hi All, I have a script which intends to create as many variables at runtime, as the number of parameters passed to it. The script needs to save these parameter values in the variables created and print them ---------- export Numbr_Parms=$# export a=1 while do export... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

4. Shell Programming and Scripting

awk/sed inserting muliple informations in one column

I'm probably sure I need to use either awk or sed judging by research but I'm not sure what exact command I have to do to do following...:wall: So this is my text file CPU 1 2 3 4 5 6 RAM 2 3 4 5 6 7 HAR 3 4 5 6 7 8 -------------- my input: Cur_CPU=10 Cur_RAM=11 Cur_HAR=13 Desired... (5 Replies)
Discussion started by: simonirang
5 Replies

5. Solaris

Command History - size, security and more informations

Hi! I need to know how to increase the size of History, creating greater security in it, and view commands with details such as date and time; Also need to know if they learn to write a 'history' command made ​​via WinSCP; Thank you! ---------- Post updated at 01:36 PM ----------... (4 Replies)
Discussion started by: poyato
4 Replies

6. Homework & Coursework Questions

Shell Script average runtime

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Make a bash script that calculates average runtime for the first two scripts you made. The average should be... (17 Replies)
Discussion started by: navlelo
17 Replies

7. Shell Programming and Scripting

shell script for finding average runtime of other script

so I've made a shell script that downloads 6 files in succession from a given url, then deletes them. Now I want to time the script, and the average time it uses by running it ~100 times. My problem is tho, how do I store the time it takes for each run through of the script? I know time writes to... (3 Replies)
Discussion started by: navlelo
3 Replies

8. Shell Programming and Scripting

execution time / runtime -- bash script please help!

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... (6 Replies)
Discussion started by: TehOne
6 Replies

9. Programming

how to programatically obtain informations about existing NICs on the system

hi, i would like to know how to programatically obtain informations about existing NICs (both configured and non-configured if possible) on *NIX? i need to write simple *NIX C/C++ program that will have these informations. i have tried to search forums (and also google) with no luck. any help... (2 Replies)
Discussion started by: nikoladsp
2 Replies

10. Shell Programming and Scripting

how to read i-node informations (date of creation)

Hi, I'm looking for a way to get the date of creation for a file. Is it possible ? I know that these informations are in the i-node but I don't know how to access them (if the 'find' command can do it with option -ctime, I have reasons to believe in it). Thanks for helping me ! (1 Reply)
Discussion started by: mullmafr
1 Replies
Login or Register to Ask a Question