Commit | Line | Data |
1716b200 |
1 | use strict; |
2 | use warnings; |
296c23ff |
3 | package Devel::REPL::Plugin::Timing; |
4 | |
6a5409bc |
5 | use Devel::REPL::Plugin; |
296c23ff |
6 | use Time::HiRes 'time'; |
aa8b7647 |
7 | use namespace::autoclean; |
296c23ff |
8 | |
9 | around '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 | |
27 | 1; |
28 | |
cfd1094b |
29 | __END__ |
30 | |
31 | =head1 NAME |
32 | |
33 | Devel::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 | |
51 | Shawn M Moore, C<< <sartak at gmail dot com> >> |
52 | |
cfd1094b |
53 | =cut |
54 | |