← Index
NYTProf Performance Profile   « line view »
For /home/ss5/perl5/perlbrew/perls/perl-5.22.0/bin/benchmarkanything-storage
  Run on Mon Jan 29 16:55:34 2018
Reported on Mon Jan 29 16:57:07 2018

Filename/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/File/Which.pm
StatementsExecuted 208 statements in 971µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
222165µs452µsFile::Which::::whichFile::Which::which
321147µs47µsFile::Which::::CORE:ftdirFile::Which::CORE:ftdir (opcode)
11116µs20µsFile::Which::::BEGIN@4File::Which::BEGIN@4
11113µs13µsFile::Which::::BEGIN@5File::Which::BEGIN@5
1119µs11µsFile::Which::::BEGIN@3File::Which::BEGIN@3
1115µs44µsFile::Which::::BEGIN@17File::Which::BEGIN@17
32115µs5µsFile::Which::::CORE:fteexecFile::Which::CORE:fteexec (opcode)
1115µs32µsFile::Which::::BEGIN@18File::Which::BEGIN@18
1114µs29µsFile::Which::::BEGIN@16File::Which::BEGIN@16
1114µs21µsFile::Which::::BEGIN@19File::Which::BEGIN@19
1112µs2µsFile::Which::::BEGIN@6File::Which::BEGIN@6
2111µs1µsFile::Which::::CORE:matchFile::Which::CORE:match (opcode)
0000s0sFile::Which::::whereFile::Which::where
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package File::Which;
2
3235µs213µs
# spent 11µs (9+2) within File::Which::BEGIN@3 which was called: # once (9µs+2µs) by File::HomeDir::BEGIN@10 at line 3
use strict;
# spent 11µs making 1 call to File::Which::BEGIN@3 # spent 2µs making 1 call to strict::import
4223µs224µs
# spent 20µs (16+4) within File::Which::BEGIN@4 which was called: # once (16µs+4µs) by File::HomeDir::BEGIN@10 at line 4
use warnings;
# spent 20µs making 1 call to File::Which::BEGIN@4 # spent 4µs making 1 call to warnings::import
5221µs113µs
# spent 13µs within File::Which::BEGIN@5 which was called: # once (13µs+0s) by File::HomeDir::BEGIN@10 at line 5
use Exporter ();
# spent 13µs making 1 call to File::Which::BEGIN@5
6267µs12µs
# spent 2µs within File::Which::BEGIN@6 which was called: # once (2µs+0s) by File::HomeDir::BEGIN@10 at line 6
use File::Spec ();
# spent 2µs making 1 call to File::Which::BEGIN@6
7
8# ABSTRACT: Perl implementation of the which utility as an API
91300nsour $VERSION = '1.19'; # VERSION
10
11
12115µsour @ISA = 'Exporter';
131500nsour @EXPORT = 'which';
141200nsour @EXPORT_OK = 'where';
15
16218µs253µs
# spent 29µs (4+24) within File::Which::BEGIN@16 which was called: # once (4µs+24µs) by File::HomeDir::BEGIN@10 at line 16
use constant IS_VMS => ($^O eq 'VMS');
# spent 29µs making 1 call to File::Which::BEGIN@16 # spent 24µs making 1 call to constant::import
17222µs282µs
# spent 44µs (5+39) within File::Which::BEGIN@17 which was called: # once (5µs+39µs) by File::HomeDir::BEGIN@10 at line 17
use constant IS_MAC => ($^O eq 'MacOS');
# spent 44µs making 1 call to File::Which::BEGIN@17 # spent 39µs making 1 call to constant::import
18217µs259µs
# spent 32µs (5+27) within File::Which::BEGIN@18 which was called: # once (5µs+27µs) by File::HomeDir::BEGIN@10 at line 18
use constant IS_DOS => ($^O eq 'MSWin32' or $^O eq 'dos' or $^O eq 'os2');
# spent 32µs making 1 call to File::Which::BEGIN@18 # spent 27µs making 1 call to constant::import
192316µs238µs
# spent 21µs (4+17) within File::Which::BEGIN@19 which was called: # once (4µs+17µs) by File::HomeDir::BEGIN@10 at line 19
use constant IS_CYG => ($^O eq 'cygwin');
# spent 21µs making 1 call to File::Which::BEGIN@19 # spent 17µs making 1 call to constant::import
20
21# For Win32 systems, stores the extensions used for
22# executable files
23# For others, the empty string is used
24# because 'perl' . '' eq 'perl' => easier
251700nsmy @PATHEXT = ('');
26if ( IS_DOS ) {
27 # WinNT. PATHEXT might be set on Cygwin, but not used.
28 if ( $ENV{PATHEXT} ) {
29 push @PATHEXT, split ';', $ENV{PATHEXT};
30 } else {
31 # Win9X or other: doesn't have PATHEXT, so needs hardcoded.
32 push @PATHEXT, qw{.com .exe .bat};
33 }
34} elsif ( IS_VMS ) {
35 push @PATHEXT, qw{.exe .com};
36} elsif ( IS_CYG ) {
37 # See this for more info
38 # http://cygwin.com/cygwin-ug-net/using-specialnames.html#pathnames-exe
39 push @PATHEXT, qw{.exe .com};
40}
41
42
43
# spent 452µs (165+288) within File::Which::which which was called 2 times, avg 226µs/call: # once (92µs+163µs) by BenchmarkAnything::Config::_read_config at line 54 of File/HomeDir.pm # once (72µs+124µs) by File::HomeDir::_DRIVER at line 28 of File/HomeDir/FreeDesktop.pm
sub which {
4422µs my ($exec) = @_;
45
462400ns return undef unless $exec;
47
4821µs my $all = wantarray;
4921µs my @results = ();
50
51 # check for aliases first
52 if ( IS_VMS ) {
53 my $symbol = `SHOW SYMBOL $exec`;
54 chomp($symbol);
55 unless ( $? ) {
56 return $symbol unless $all;
57 push @results, $symbol;
58 }
59 }
60 if ( IS_MAC ) {
61 my @aliases = split /\,/, $ENV{Aliases};
62 foreach my $alias ( @aliases ) {
63 # This has not been tested!!
64 # PPT which says MPW-Perl cannot resolve `Alias $alias`,
65 # let's just hope it's fixed
66 if ( lc($alias) eq lc($exec) ) {
67 chomp(my $file = `Alias $alias`);
68 last unless $file; # if it failed, just go on the normal way
69 return $file unless $all;
70 push @results, $file;
71 # we can stop this loop as if it finds more aliases matching,
72 # it'll just be the same result anyway
73 last;
74 }
75 }
76 }
77
78210µs21µs return $exec
# spent 1µs making 2 calls to File::Which::CORE:match, avg 650ns/call
79 if !IS_VMS and !IS_MAC and !IS_DOS and $exec =~ /\// and -f $exec and -x $exec;
80
81211µs225µs my @path = File::Spec->path;
# spent 25µs making 2 calls to File::Spec::Unix::path, avg 12µs/call
82 if ( IS_DOS or IS_VMS or IS_MAC ) {
83 unshift @path, File::Spec->curdir;
84 }
85
8644269µs168315µs foreach my $base ( map { File::Spec->catfile($_, $exec) } @path ) {
# spent 210µs making 42 calls to File::Spec::Unix::catfile, avg 5µs/call # spent 76µs making 42 calls to File::Spec::Unix::catdir, avg 2µs/call # spent 28µs making 84 calls to File::Spec::Unix::canonpath, avg 338ns/call
87328µs for my $ext ( @PATHEXT ) {
88327µs my $file = $base.$ext;
89
90 # We don't want dirs (as they are -x)
913274µs3247µs next if -d $file;
# spent 47µs making 32 calls to File::Which::CORE:ftdir, avg 1µs/call
92
933235µs325µs if (
# spent 5µs making 32 calls to File::Which::CORE:fteexec, avg 147ns/call
94 # Executable, normal case
95 -x _
96 or (
97 # MacOS doesn't mark as executable so we check -e
98 IS_MAC
99 ||
100 (
101 ( IS_DOS or IS_CYG )
102 and
103 grep {
104 $file =~ /$_\z/i
105 } @PATHEXT[1..$#PATHEXT]
106 )
107 # DOSish systems don't pass -x on
108 # non-exe/bat/com files. so we check -e.
109 # However, we don't want to pass -e on files
110 # that aren't in PATHEXT, like README.
111 and -e _
112 )
113 ) {
114210µs return $file unless $all;
115 push @results, $file;
116 }
117 }
118 }
119
120 if ( $all ) {
121 return @results;
122 } else {
123 return undef;
124 }
125}
126
127
128sub where {
129 # force wantarray
130 my @res = which($_[0]);
131 return @res;
132}
133
13416µs1;
135
136__END__
 
# spent 47µs within File::Which::CORE:ftdir which was called 32 times, avg 1µs/call: # 32 times (47µs+0s) by File::Which::which at line 91, avg 1µs/call
sub File::Which::CORE:ftdir; # opcode
# spent 5µs within File::Which::CORE:fteexec which was called 32 times, avg 147ns/call: # 32 times (5µs+0s) by File::Which::which at line 93, avg 147ns/call
sub File::Which::CORE:fteexec; # opcode
# spent 1µs within File::Which::CORE:match which was called 2 times, avg 650ns/call: # 2 times (1µs+0s) by File::Which::which at line 78, avg 650ns/call
sub File::Which::CORE:match; # opcode