From e76b691e78e273226cba9284cb8cd22a423319ed Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 2 Aug 2013 17:23:25 -0500 Subject: bucky2 --- bucky2/lib/Time/Stopwatch.pm | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 bucky2/lib/Time/Stopwatch.pm (limited to 'bucky2/lib/Time/Stopwatch.pm') diff --git a/bucky2/lib/Time/Stopwatch.pm b/bucky2/lib/Time/Stopwatch.pm new file mode 100644 index 0000000..b7cec26 --- /dev/null +++ b/bucky2/lib/Time/Stopwatch.pm @@ -0,0 +1,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; -- cgit v1.2.3-70-g09d2