[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Time in Milliseconds

Posted on 1999-01-27
5
Medium Priority
?
11,342 Views
Last Modified: 2008-03-17
I'm using a perl script to time things with code like $startmain=time; at the beginning and at the end of what I want to time.  Time seems to be limited to a minimum value of seconds, while I would like to measure down to the millisecond.  Is there a way to do this?

One oddment I found also is that when I want to establish the date and I use gmtime(time)=($var ...), I have to increment the month by 1 to get the current month.  Does anyone know why this is?
0
Comment
Question by:wilfrieds
  • 2
  • 2
5 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1210327
use perl's times builtin command (see Camel book).

> I have to increment the month by 1 to get the current month
'cause the month is returned in C-style indexing: 0..11
0
 
LVL 1

Author Comment

by:wilfrieds
ID: 1210328
ahoffmann : times seems to provide me only with CPU times, where for this particular reason I want the total lapse time of the script - is there something else you are aware of?
0
 
LVL 85

Expert Comment

by:ozo
ID: 1210329
perldoc -q 'time.*second'

=head1 Found in perlfaq8.pod

=head2 How can I measure time under a second?

In general, you may not be able to.  The Time::HiRes module (available
from CPAN) provides this functionality for some systems.

In general, you may not be able to.  But if your system supports both the
syscall() function in Perl as well as a system call like gettimeofday(2),
then you may be able to do something like this:

    require 'sys/syscall.ph';

    $TIMEVAL_T = "LL";

    $done = $start = pack($TIMEVAL_T, ());

    syscall( &SYS_gettimeofday, $start, 0)) != -1
               or die "gettimeofday: $!";

       ##########################
       # DO YOUR OPERATION HERE #
       ##########################

    syscall( &SYS_gettimeofday, $done, 0) != -1
           or die "gettimeofday: $!";

    @start = unpack($TIMEVAL_T, $start);
    @done  = unpack($TIMEVAL_T, $done);

    # fix microseconds
    for ($done[1], $start[1]) { $_ /= 1_000_000 }

    $delta_time = sprintf "%.4f", ($done[0]  + $done[1]  )
                                            -
                                 ($start[0] + $start[1] );

0
 
LVL 1

Author Comment

by:wilfrieds
ID: 1210330
thanks ozo
i 'll accept your answer if you care to post your comment as an answer
0
 
LVL 85

Accepted Solution

by:
ozo earned 200 total points
ID: 1210331
If you're trying to benchmark a piece of code, you might also
use Benchmark;
which lets you run the code a number of times to get a more precise timing.
0

Featured Post

Independent Software Vendors: 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

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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
Suggested Courses

873 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