summaryrefslogtreecommitdiff
path: root/search/lib/Time/Stopwatch.pm
blob: b7cec26491aad61ed6d4ab2fbb0fa026a5edeec9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
################################################3
package Time::Stopwatch;
my $VERSION = '1.00';
use strict;
use constant HIRES => eval { local $SIG{__DIE__}; require Time::HiRes };
sub TIESCALAR { my $pkg = shift;
    my $time = (HIRES ? Time::HiRes::time() : time()) - (@_ ? shift() : 0);
    bless \$time, $pkg; }
sub FETCH { (HIRES ? Time::HiRes::time() : time()) - ${$_[0]}; }
sub STORE { ${$_[0]} = (HIRES ? Time::HiRes::time() : time()) - $_[1]; }
#################################################
sub print_timer { print sprintf "%3.2f s %s\n", shift, shift; }
1;