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