← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:11 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/String/Format.pm
StatementsExecuted 10247 statements in 15.2ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
445117.96ms29.9msString::Format::::stringfString::Format::stringf
445117.28ms18.5msString::Format::::_replaceString::Format::_replace
445111.39ms1.39msString::Format::::CORE:substString::Format::CORE:subst (opcode)
89011758µs758µsString::Format::::CORE:substcontString::Format::CORE:substcont (opcode)
44511662µs662µsString::Format::::CORE:regcompString::Format::CORE:regcomp (opcode)
11112µs24µsString::Format::::BEGIN@21String::Format::BEGIN@21
1117µs20µsString::Format::::BEGIN@23String::Format::BEGIN@23
1117µs56µsString::Format::::BEGIN@24String::Format::BEGIN@24
1116µs35µsString::Format::::BEGIN@22String::Format::BEGIN@22
1112µs2µsString::Format::::CORE:qrString::Format::CORE:qr (opcode)
0000s0sString::Format::::__ANON__[:93]String::Format::__ANON__[:93]
0000s0sString::Format::::stringfactoryString::Format::stringfactory
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package String::Format;
2
3# ----------------------------------------------------------------------
4# Copyright (C) 2002,2009 darren chamberlain <darren@cpan.org>
5#
6# This program is free software; you can redistribute it and/or
7# modify it under the terms of the GNU General Public License as
8# published by the Free Software Foundation; version 2.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18# 02110-1301 USA.
19# -------------------------------------------------------------------
20
21230µs236µs
# spent 24µs (12+12) within String::Format::BEGIN@21 which was called: # once (12µs+12µs) by Perl::Critic::Violation::BEGIN@21 at line 21
use strict;
# spent 24µs making 1 call to String::Format::BEGIN@21 # spent 12µs making 1 call to strict::import
22222µs263µs
# spent 35µs (6+28) within String::Format::BEGIN@22 which was called: # once (6µs+28µs) by Perl::Critic::Violation::BEGIN@21 at line 22
use vars qw($VERSION @EXPORT);
# spent 35µs making 1 call to String::Format::BEGIN@22 # spent 28µs making 1 call to vars::import
23221µs233µs
# spent 20µs (7+13) within String::Format::BEGIN@23 which was called: # once (7µs+13µs) by Perl::Critic::Violation::BEGIN@21 at line 23
use Exporter;
# spent 20µs making 1 call to String::Format::BEGIN@23 # spent 13µs making 1 call to Exporter::import
242299µs2104µs
# spent 56µs (7+48) within String::Format::BEGIN@24 which was called: # once (7µs+48µs) by Perl::Critic::Violation::BEGIN@21 at line 24
use base qw(Exporter);
# spent 56µs making 1 call to String::Format::BEGIN@24 # spent 48µs making 1 call to base::import
25
261600ns$VERSION = '1.17';
271700ns@EXPORT = qw(stringf);
28
29
# spent 18.5ms (7.28+11.2) within String::Format::_replace which was called 445 times, avg 42µs/call: # 445 times (7.28ms+11.2ms) by String::Format::stringf at line 85, avg 42µs/call
sub _replace {
30445754µs my ($args, $orig, $alignment, $min_width,
31 $max_width, $passme, $formchar) = @_;
32
33 # For unknown escapes, return the orignial
34445161µs return $orig unless defined $args->{$formchar};
35
36445110µs $alignment = '+' unless defined $alignment;
37
38445201µs my $replacement = $args->{$formchar};
39445228µs if (ref $replacement eq 'CODE') {
40 # $passme gets passed to subrefs.
4144557µs $passme ||= "";
42445126µs $passme =~ tr/{}//d;
43445645µs44511.2ms $replacement = $replacement->($passme);
# spent 11.2ms making 445 calls to Perl::Critic::Policy::__ANON__[Perl/Critic/Policy.pm:467], avg 25µs/call
44 }
45
46445131µs my $replength = length $replacement;
4744548µs $min_width ||= $replength;
4844545µs $max_width ||= $replength;
49
50 # length of replacement is between min and max
5144551µs if (($replength > $min_width) && ($replength < $max_width)) {
52 return $replacement;
53 }
54
55 # length of replacement is longer than max; truncate
5644510µs if ($replength > $max_width) {
57 return substr($replacement, 0, $max_width);
58 }
59
60 # length of replacement is less than min: pad
6144570µs if ($alignment eq '-') {
62 # left align; pad in front
63 return $replacement . " " x ($min_width - $replength);
64 }
65
66 # right align, pad at end
674451.20ms return " " x ($min_width - $replength) . $replacement;
68}
69
7019µs12µsmy $regex = qr/
# spent 2µs making 1 call to String::Format::CORE:qr
71 (% # leading '%'
72 (-)? # left-align, rather than right
73 (\d*)? # (optional) minimum field width
74 (?:\.(\d*))? # (optional) maximum field width
75 ({.*?})? # (optional) stuff inside
76 (\S) # actual format character
77 )/x;
78
# spent 29.9ms (7.96+21.9) within String::Format::stringf which was called 445 times, avg 67µs/call: # 445 times (7.96ms+21.9ms) by Perl::Critic::Policy::to_string at line 478 of Perl/Critic/Policy.pm, avg 67µs/call
sub stringf {
79445144µs my $format = shift || return;
804452.48ms445612µs my $args = UNIVERSAL::isa($_[0], 'HASH') ? shift : { @_ };
# spent 612µs making 445 calls to UNIVERSAL::isa, avg 1µs/call
81445326µs $args->{'n'} = "\n" unless exists $args->{'n'};
8244585µs $args->{'t'} = "\t" unless exists $args->{'t'};
83445182µs $args->{'%'} = "%" unless exists $args->{'%'};
84
858906.23ms222521.3ms $format =~ s/$regex/_replace($args, $1, $2, $3, $4, $5, $6)/ge;
# spent 18.5ms making 445 calls to String::Format::_replace, avg 42µs/call # spent 1.39ms making 445 calls to String::Format::CORE:subst, avg 3µs/call # spent 758µs making 890 calls to String::Format::CORE:substcont, avg 852ns/call # spent 662µs making 445 calls to String::Format::CORE:regcomp, avg 1µs/call
86
874451.48ms return $format;
88}
89
90sub stringfactory {
91 shift; # It's a class method, but we don't actually want the class
92 my $args = UNIVERSAL::isa($_[0], "HASH") ? shift : { @_ };
93 return sub { stringf($_[0], $args) };
94}
95
9613µs1;
97__END__
 
# spent 2µs within String::Format::CORE:qr which was called: # once (2µs+0s) by Perl::Critic::Violation::BEGIN@21 at line 70
sub String::Format::CORE:qr; # opcode
# spent 662µs within String::Format::CORE:regcomp which was called 445 times, avg 1µs/call: # 445 times (662µs+0s) by String::Format::stringf at line 85, avg 1µs/call
sub String::Format::CORE:regcomp; # opcode
# spent 1.39ms within String::Format::CORE:subst which was called 445 times, avg 3µs/call: # 445 times (1.39ms+0s) by String::Format::stringf at line 85, avg 3µs/call
sub String::Format::CORE:subst; # opcode
# spent 758µs within String::Format::CORE:substcont which was called 890 times, avg 852ns/call: # 890 times (758µs+0s) by String::Format::stringf at line 85, avg 852ns/call
sub String::Format::CORE:substcont; # opcode