Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Timer subtraction (UPDATED)

by thanos1983 (Vicar)
on Oct 06, 2017 at 08:25 UTC ( #1200804=note: print w/replies, xml ) Need Help??

in reply to Timer subtraction

Hello Anonymous Monk,

I think you are looking for How do I find difference between two timestamps?.

Update: Thanks to the idea of the fellow Monk haukex that you might want to measure the process time of your script between two points. In this case you can use Time::HiRes. If this is the case it can give you accuracy down to microseconds.

Sample of code below:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use feature 'say'; use Time::HiRes qw(gettimeofday tv_interval); # measure elapsed time say 'Start counting'; my $t0 = [gettimeofday]; # do bunch of stuff here say 'I am doing my things here that I want to know the process time... +'; my $t1 = [gettimeofday]; say 'Finished counting'; print Dumper $t0; print Dumper $t1; my $t0_t1 = tv_interval $t0, $t1; say $t0_t1; my $elapsed = tv_interval ($t0, [gettimeofday]); say $elapsed; # $elapsed = tv_interval ($t0); # equivalent code __END__ $ perl Start counting I am doing my things here that I want to know the process time... Finished counting $VAR1 = [ 1507287063, 951261 ]; $VAR1 = [ 1507287063, 951274 ]; 1.3e-05 8.6e-05

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1200804]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2018-07-18 01:23 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (383 votes). Check out past polls.