Solved

time difference in milliseconds

Posted on 2004-08-20
3
10,294 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 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

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

Suggested Solutions

Title # Comments Views Activity
Passing shell scripts to run on the SFTP cmd object 12 189
How to strip .csv from file name 9 84
batch script for automated email 12 133
PERL - Find newest folder 12 166
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…

763 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