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

time difference in milliseconds

How can I calculate time difference in milliseconds?
0
desktop2
Asked:
desktop2
1 Solution
 
jmcgOwnerCommented:
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
 
JustinPincarCommented:
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
 
mishagaleCommented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now