Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Linux and Unix
Tag Cloud
access audio black screen blue screen boot bsod connection crash dell desktop driver drivers dvd email error excel excel 2003 firefox hard drive hardware hijackthis internet keyboard laptop malware monitor motherboard network networking outlook problem recovery router safe mode screen slow sound spyware trojan upgrade vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
Timing an operation

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
Matthew_S's Avatar
Junior Member with 10 posts.
 
Join Date: May 2007
24-May-2007, 07:31 AM #1
Timing an operation
Hi all,

I'm fairly new to Linux and Bash so if I appear slow that's the reason

I'm trying to write a function in Bash that will give me the time it takes to do an operation and then report to a logfile if it passes or fails. What I have so far is;

functionName()
{
echo Timing the operation. >> $LOG
date
$OPERATION
date
}

but this means I will manually have to calculate the difference between the two dates. Can i have something like;

if
difference between dates <5seconds
echo fail
fi

??

Thanks in advance,

Matthew.
linuxphile's Avatar
Administrator with 413 posts.
 
Join Date: Mar 2003
Location: MD
Experience: Intermediate
25-May-2007, 07:15 AM #2
#!/bin/bash
start=$(date +%s)
end=$(date +%s)
DIFF=$(( $end - $start))
echo “It took $DIFF seconds”
lotuseclat79's Avatar
Distinguished Member with 14,984 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
28-May-2007, 08:25 AM #3
Look into the "time" command to distinguish the difference between real, user and system time for any operation.

The date command only gives you the wall time of the operation and does not distinguish the details like the "time" command.

-- Tom
Closed Thread Bookmark and Share

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 10:53 AM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.