Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- #
- # Small operation timer used to check how much time individual
- # operations took when $debug is set to 1.
- #
- package otimer;
- use Time::HiRes qw(gettimeofday tv_interval);
- sub new
- {
- my $class = shift;
- my $self = { _start_ts => [gettimeofday()] };
- bless $self, $class;
- return $self;
- }
- sub ellapsed
- {
- my ($self) = @_;
- return tv_interval($self->{_start_ts}, [gettimeofday()]);
- }
- sub DESTROY
- {
- my ($self) = @_;
- printf("<took %.2f seconds>\n", $self->ellapsed())
- if $debug;
- }
- }
- # Example
- $debug = 1;
- foreach(@files) {
- my $benchmark = otimer->new();
- do_something();
- }
Advertisement
Add Comment
Please, Sign In to add comment