• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6099
  • Last Modified:

get milliseconds in linux

how can i get milliseconds from bash, i will use it in a script, i can't write c++
0
inudaci
Asked:
inudaci
  • 4
  • 3
  • 2
  • +1
1 Solution
 
majorwooCommented:
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
0
 
GnsCommented:
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
0
 
inudaciAuthor Commented:
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?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
naccadCommented:
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
0
 
inudaciAuthor Commented:
im sure that would work, never installed a pm for perl before though.. i don't know if i wanna go down that path

0
 
naccadCommented:
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
0
 
majorwooCommented:


time wget filename

time will do just what it says, time how long the command wget takes -> its much more accurate then using two timestamps
0
 
inudaciAuthor Commented:
ok, thanks every one. and thanks for the installing module manual but,
that 'time wget..' is exactly what i was looking for.
0
 
inudaciAuthor Commented:
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.
0
 
majorwooCommented:
hmm, i got a C for "exactly what I was looking for"

what was it you did want then?
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now