shadowm

Untitled

Sep 19th, 2012
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.64 KB | None | 0 0
  1. {
  2.     #
  3.     # Small operation timer used to check how much time individual
  4.     # operations took when $debug is set to 1.
  5.     #
  6.  
  7.     package otimer;
  8.  
  9.     use Time::HiRes qw(gettimeofday tv_interval);
  10.  
  11.     sub new
  12.     {
  13.         my $class = shift;
  14.         my $self = { _start_ts => [gettimeofday()] };
  15.  
  16.         bless $self, $class;
  17.  
  18.         return $self;
  19.     }
  20.  
  21.     sub ellapsed
  22.     {
  23.         my ($self) = @_;
  24.  
  25.         return tv_interval($self->{_start_ts}, [gettimeofday()]);
  26.     }
  27.  
  28.     sub DESTROY
  29.     {
  30.         my ($self) = @_;
  31.  
  32.         printf("<took %.2f seconds>\n", $self->ellapsed())
  33.             if $debug;
  34.     }
  35. }
  36.  
  37. # Example
  38.  
  39. $debug = 1;
  40.  
  41. foreach(@files) {
  42.     my $benchmark = otimer->new();
  43.     do_something();
  44. }
Advertisement
Add Comment
Please, Sign In to add comment