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 acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming google gpu hard drive hardware hdmi internet laptop malware memory monitor motherboard netgear network printer problem ram registry repair router security slow software sound trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
Timing an operation

Reply  
Thread Tools
Matthew_S's Avatar
Junior Member with 10 posts.
 
Join Date: May 2007
24-May-2007, 08: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 429 posts.
 
Join Date: Mar 2003
Location: MD
Experience: Intermediate
25-May-2007, 08: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 21,345 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
28-May-2007, 09: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
Reply

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.

Search Tech Support Guy

Find the solution to your
computer problem!




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



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 02:39 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.