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