Solved

time difference in milliseconds

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
use perl to insert into MySQL database 9 144
Using Perl to parse rows 7 97
what are these modules in perl script 4 103
create a gui in perl 3 97
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…

809 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