Link to home
Start Free TrialLog in
Avatar of inudaci
inudaci

asked on

get milliseconds in linux

how can i get milliseconds from bash, i will use it in a script, i can't write c++
Avatar of majorwoo
majorwoo

millisenods for the current(system) time or what?

you will need to look into a POSIX kernel if you want to do anything really fancy
If it is for below second timing, try
man usleep
try with
time usleep 100000<Enter>

Otherwise describe in more detail what you're after (or rather why;-).

-- Glenn
Avatar of inudaci

ASKER

startTime=`date +%s`
wget fileaddress
endTime=`date +%s`

downloadTime=$(($endTime-$startTime))

the start/end variables are specified in seconds.
i really need to get that in milliseconds or 1/100 of a second. Do you know how i can achieve this?
I never did that in bash but you can achive that in perl
using the Time::HiRes Module

use Time::HiRes qw( gettimeofday tv_interval );
my $t0 = [gettimeofday];
`wget fileaddress`;
my $t1 = [gettimeofday];
my $elasped = tv_interval ( $t0, $t1);
print "$elasped\n";

hope that helps.
-nick
Avatar of inudaci

ASKER

im sure that would work, never installed a pm for perl before though.. i don't know if i wanna go down that path

u can use the CPAN module for that, its actully easy
if u have a minute give it a try

perl -MCPAN -eshell

install Time::HiRes


it will even guide u thru any needed dependencies
im not even sure that u need to install this one separate or
if it comes with your perl distro

like i said, give it try 1st

tc
-nick
ASKER CERTIFIED SOLUTION
Avatar of majorwoo
majorwoo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of inudaci

ASKER

ok, thanks every one. and thanks for the installing module manual but,
that 'time wget..' is exactly what i was looking for.
Avatar of inudaci

ASKER

just for the reference.

in the case of wget, the best way to get the actual download time, is not to use time wget. That times the whole process of connecting too. If you only want the actual download time, use download rate calculated with the file size.
hmm, i got a C for "exactly what I was looking for"

what was it you did want then?