make room for $VERSION after package declaration (newer [PkgVersion] requires it)
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / Timing.pm
CommitLineData
1716b200 1use strict;
2use warnings;
296c23ff 3package Devel::REPL::Plugin::Timing;
4
6a5409bc 5use Devel::REPL::Plugin;
296c23ff 6use Time::HiRes 'time';
aa8b7647 7use namespace::autoclean;
296c23ff 8
9around 'eval' => sub {
10 my $orig = shift;
11 my ($self, $line) = @_;
12
13 my @ret;
14 my $start = time;
15
16 if (wantarray) {
17 @ret = $self->$orig($line);
18 }
19 else {
20 $ret[0] = $self->$orig($line);
21 }
22
23 $self->print("Took " . (time - $start) . " seconds.\n");
24 return @ret;
25};
26
271;
28
cfd1094b 29__END__
30
31=head1 NAME
32
33Devel::REPL::Plugin::Timing - display execution times
34
e4761e81 35=head1 SYNOPSIS
36
37 # in your re.pl file:
38 use Devel::REPL;
39 my $repl = Devel::REPL->new;
40 $repl->load_plugin('Timing');
41
42 # after you run re.pl:
43 $ sum map $_*100, 1..100000;
44 Took 0.0830280780792236 seconds.
45 500005000000
46
47 $
48
30b459d4 49=head1 AUTHOR
50
51Shawn M Moore, C<< <sartak at gmail dot com> >>
52
cfd1094b 53=cut
54