[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

time difference in milliseconds

Posted on 2004-08-20
3
Medium Priority
?
10,357 Views
Last Modified: 2008-01-09
How can I calculate time difference in milliseconds?
0
Comment
Question by:desktop2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 20

Accepted Solution

by:
jmcg earned 500 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

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Six Sigma Control Plans

656 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