http://www.perlmonks.org?node_id=1200804


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 test.pl 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!