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

x
?
Solved

Time in Milliseconds

Posted on 1999-01-27
5
Medium Priority
?
11,338 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
[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
  • 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 84

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 84

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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

649 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