Solved

time difference in milliseconds

Posted on 2004-08-20
3
10,250 Views
Last Modified: 2008-01-09
How can I calculate time difference in milliseconds?
0
Comment
Question by:desktop2
3 Comments
 
LVL 20

Accepted Solution

by:
jmcg earned 125 total points
ID: 11857889
To calculate a time difference, you need a way to get time values. The most portable way is to use the Time::HiRes module

http://search.cpan.org/~jhi/Time-HiRes-1.60/HiRes.pm

I think the methods 'gettimeofday' and 'tv_interval' are most likely to be of use to you. The time structure used is nominally in microseconds, so if you're not using the floating-point representation given by tv_interval, you may need to divide the microsecond parts by 1000 to express the interval in milliseconds.

Also be aware that on many current systems, the actual timer resolution is more like 10ms than 1 ms.

0
 
LVL 1

Expert Comment

by:JustinPincar
ID: 11859879
I would just use time() and/or $^T (special variable for start of script time).

So if you wanted to find execution time of a script up until a point you could do:
$time = time() - $^T;

I think that gives it in seconds though, so multiply by 1000?
I haven't tried saving time() to a variable when i start something, but I'm guessing that you could also just do $time1=time() somewhere in your script, and then $time2=time() later, and then subtract to get the time elapsed.

~Justin
0
 
LVL 2

Expert Comment

by:mishagale
ID: 11859942
JustinPincar's solution sort of works, but I suspect this is not what you want, as the resolution of your time variables will never be better than 1000 millisecs - use
Time::HiRes
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now