summaryrefslogtreecommitdiff
path: root/search/lib/Time/Stopwatch.pm
diff options
context:
space:
mode:
Diffstat (limited to 'search/lib/Time/Stopwatch.pm')
-rw-r--r--search/lib/Time/Stopwatch.pm13
1 files changed, 13 insertions, 0 deletions
diff --git a/search/lib/Time/Stopwatch.pm b/search/lib/Time/Stopwatch.pm
new file mode 100644
index 0000000..b7cec26
--- /dev/null
+++ b/search/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;