← Index
NYTProf Performance Profile   « line view »
For split.pl
  Run on Thu Apr 20 02:05:47 2023
Reported on Thu Apr 20 18:31:10 2023

Filename/home/hejohns/perl5/lib/perl5/Data/Printer.pm
StatementsExecuted 47 statements in 1.15ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1113.46ms11.8msData::Printer::::BEGIN@4Data::Printer::BEGIN@4
1111.46ms1.50msData::Printer::::BEGIN@6Data::Printer::BEGIN@6
11113µs247µsData::Printer::::importData::Printer::import
1118µs24µsData::Printer::::BEGIN@47Data::Printer::BEGIN@47
1117µs8µsData::Printer::::BEGIN@2Data::Printer::BEGIN@2
1116µs11µsData::Printer::::BEGIN@39Data::Printer::BEGIN@39
1116µs219µsData::Printer::::_initializeData::Printer::_initialize
1115µs6µsData::Printer::::BEGIN@5Data::Printer::BEGIN@5
1114µs14µsData::Printer::::BEGIN@60Data::Printer::BEGIN@60
2213µs3µsData::Printer::::_find_optionData::Printer::_find_option
1113µs15µsData::Printer::::BEGIN@3Data::Printer::BEGIN@3
0000s0sData::Printer::::__ANON__[:47]Data::Printer::__ANON__[:47]
0000s0sData::Printer::::__ANON__[:69]Data::Printer::__ANON__[:69]
0000s0sData::Printer::::__ANON__[:73]Data::Printer::__ANON__[:73]
0000s0sData::Printer::::_fetch_args_withData::Printer::_fetch_args_with
0000s0sData::Printer::::_handle_outputData::Printer::_handle_output
0000s0sData::Printer::::_p_without_prototypesData::Printer::_p_without_prototypes
0000s0sData::Printer::::npData::Printer::np
0000s0sData::Printer::::pData::Printer::p
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Data::Printer;
2215µs210µs
# spent 8µs (7+1) within Data::Printer::BEGIN@2 which was called: # once (7µs+1µs) by main::BEGIN@48 at line 2
use strict;
# spent 8µs making 1 call to Data::Printer::BEGIN@2 # spent 1µs making 1 call to strict::import
3212µs227µs
# spent 15µs (3+12) within Data::Printer::BEGIN@3 which was called: # once (3µs+12µs) by main::BEGIN@48 at line 3
use warnings;
# spent 15µs making 1 call to Data::Printer::BEGIN@3 # spent 12µs making 1 call to warnings::import
4277µs211.8ms
# spent 11.8ms (3.46+8.38) within Data::Printer::BEGIN@4 which was called: # once (3.46ms+8.38ms) by main::BEGIN@48 at line 4
use Data::Printer::Object;
# spent 11.8ms making 1 call to Data::Printer::BEGIN@4 # spent 1µs making 1 call to Data::Printer::__ANON__
5215µs26µs
# spent 6µs (5+200ns) within Data::Printer::BEGIN@5 which was called: # once (5µs+200ns) by main::BEGIN@48 at line 5
use Data::Printer::Common;
# spent 6µs making 1 call to Data::Printer::BEGIN@5 # spent 200ns making 1 call to Data::Printer::__ANON__
62177µs21.50ms
# spent 1.50ms (1.46+40µs) within Data::Printer::BEGIN@6 which was called: # once (1.46ms+40µs) by main::BEGIN@48 at line 6
use Data::Printer::Config;
# spent 1.50ms making 1 call to Data::Printer::BEGIN@6 # spent 700ns making 1 call to Data::Printer::__ANON__
7
81200nsour $VERSION = '1.001000';
9122µs$VERSION = eval $VERSION;
# spent 2µs executing statements in string eval
10
111100nsmy $rc_arguments;
12my %arguments_for;
13
14
# spent 247µs (13+234) within Data::Printer::import which was called: # once (13µs+234µs) by main::BEGIN@48 at line 48 of /home/hejohns/documentsNoSync/22f/490/gradescope-utils/bin/split.pl
sub import {
151300ns my $class = shift;
16
171500ns1219µs _initialize();
# spent 219µs making 1 call to Data::Printer::_initialize
18
191200ns my $args;
201300ns if (@_ > 0) {
21 $args = @_ == 1 ? shift : {@_};
22 Data::Printer::Common::_warn(
23 undef,
24 'Data::Printer can receive either a hash or a hash reference'
25 ) unless ref $args eq 'HASH';
26 $args = Data::Printer::Config::_expand_profile($args)
27 if exists $args->{profile};
28 }
29
30 # every time you load it, we override the version from *your* caller
3111µs111µs my $caller = caller;
321600ns $arguments_for{$caller} = $args;
33
341800ns12µs my $use_prototypes = _find_option('use_prototypes', $args, $caller, 1);
# spent 2µs making 1 call to Data::Printer::_find_option
351500ns my $exported = ($use_prototypes ? \&p : \&_p_without_prototypes);
36
371400ns11µs my $imported = _find_option('alias', $args, $caller, 'p');
# spent 1µs making 1 call to Data::Printer::_find_option
38
39364µs216µs
# spent 11µs (6+5) within Data::Printer::BEGIN@39 which was called: # once (6µs+5µs) by main::BEGIN@48 at line 39
{ no strict 'refs';
# spent 11µs making 1 call to Data::Printer::BEGIN@39 # spent 5µs making 1 call to strict::unimport
4012µs *{"$caller\::$imported"} = $exported;
4111µs *{"$caller\::np"} = \&np;
42 }
43}
44
45
# spent 219µs (6+213) within Data::Printer::_initialize which was called: # once (6µs+213µs) by Data::Printer::import at line 17
sub _initialize {
46 # potential race but worst case is we read it twice :)
47479µs239µs
# spent 24µs (8+15) within Data::Printer::BEGIN@47 which was called: # once (8µs+15µs) by main::BEGIN@48 at line 47
{ no warnings 'redefine'; *_initialize = sub {} }
# spent 24µs making 1 call to Data::Printer::BEGIN@47 # spent 15µs making 1 call to warnings::unimport
48
491600ns1208µs my $rc_filename = Data::Printer::Config::_get_first_rc_file_available();
501700ns15µs $rc_arguments = Data::Printer::Config::load_rc_file($rc_filename);
# spent 5µs making 1 call to Data::Printer::Config::load_rc_file
51
5212µs if (
53 exists $rc_arguments->{'_'}{live_update}
54 && defined $rc_arguments->{'_'}{live_update}
55 && $rc_arguments->{'_'}{live_update} =~ /\A\d+\z/
56 && $rc_arguments->{'_'}{live_update} > 0) {
57 my $now = time;
58 my $last_mod = (stat $rc_filename)[9];
59 {
602666µs225µs
# spent 14µs (4+10) within Data::Printer::BEGIN@60 which was called: # once (4µs+10µs) by main::BEGIN@48 at line 60
no warnings 'redefine';
# spent 14µs making 1 call to Data::Printer::BEGIN@60 # spent 10µs making 1 call to warnings::unimport
61 *_initialize = sub {
62 if (time - $now > $rc_arguments->{'_'}{live_update}) {
63 my $new_last_mod = (stat $rc_filename)[9];
64 if (defined $new_last_mod && $new_last_mod > $last_mod) {
65 $now = time;
66 $last_mod = $new_last_mod;
67 $rc_arguments = Data::Printer::Config::load_rc_file($rc_filename);
68 if (!exists $rc_arguments->{'_'}{live_update} || !$rc_arguments->{'_'}{live_update}) {
69 *_initialize = sub {};
70 }
71 }
72 }
73 };
74 }
75 }
76}
77
78sub np (\[@$%&];%) {
79 my (undef, %properties) = @_;
80
81 _initialize();
82
83 my $caller = caller;
84 my $args_to_use = _fetch_args_with($caller, \%properties);
85 return '' if $args_to_use->{quiet};
86 my $printer = Data::Printer::Object->new($args_to_use);
87
88 # force color level 0 on 'auto' colors:
89 if ($printer->colored eq 'auto') {
90 $printer->{_output_color_level} = 0;
91 }
92
93 my $ref = ref $_[0];
94 if ($ref eq 'ARRAY' || $ref eq 'HASH' || ($ref eq 'REF' && ref ${$_[0]} eq 'REF')) {
95 $printer->{_refcount_base}++;
96 }
97 my $output = $printer->parse($_[0]);
98 if ($printer->caller_message_position eq 'after') {
99 $output .= $printer->_write_label;
100 }
101 else {
102 $output = $printer->_write_label . $output;
103 }
104 return $output;
105}
106
107
108sub p (\[@$%&];%) {
109 my (undef, %properties) = @_;
110
111 _initialize();
112
113 my $caller = caller;
114 my $args_to_use = _fetch_args_with($caller, \%properties);
115 return if $args_to_use->{quiet};
116 my $printer = Data::Printer::Object->new($args_to_use);
117 my $want_value = defined wantarray;
118 if ($printer->colored eq 'auto' && $printer->return_value eq 'dump' && $want_value) {
119 $printer->{_output_color_level} = 0;
120 }
121
122 my $ref = ref $_[0];
123 if ($ref eq 'ARRAY' || $ref eq 'HASH' || ($ref eq 'REF' && ref ${$_[0]} eq 'REF')) {
124 $printer->{_refcount_base}++;
125 }
126 my $output = $printer->parse($_[0]);
127 if ($printer->caller_message_position eq 'after') {
128 $output .= $printer->_write_label;
129 }
130 else {
131 $output = $printer->_write_label . $output;
132 }
133
134 return _handle_output($printer, $output, $want_value, $_[0]);
135}
136
137# This is a p() clone without prototypes. Just like regular Data::Dumper,
138# this version expects a reference as its first argument. We make a single
139# exception for when we only get one argument, in which case we ref it
140# for the user and keep going.
141sub _p_without_prototypes {
142 my (undef, %properties) = @_;
143
144 my $item;
145 if (!ref $_[0] && @_ == 1) {
146 my $item_value = $_[0];
147 $item = \$item_value;
148 }
149
150 _initialize();
151
152 my $caller = caller;
153 my $args_to_use = _fetch_args_with($caller, \%properties);
154 return if $args_to_use->{quiet};
155 my $printer = Data::Printer::Object->new($args_to_use);
156
157 my $want_value = defined wantarray;
158 if ($printer->colored eq 'auto' && $printer->return_value eq 'dump' && $want_value) {
159 $printer->{_output_color_level} = 0;
160 }
161
162 my $ref = ref( defined $item ? $item : $_[0] );
163 if ($ref eq 'ARRAY' || $ref eq 'HASH' || ($ref eq 'REF'
164 && ref(defined $item ? $item : ${$_[0]}) eq 'REF')) {
165 $printer->{_refcount_base}++;
166 }
167 my $output = $printer->parse((defined $item ? $item : $_[0]));
168 if ($printer->caller_message_position eq 'after') {
169 $output .= $printer->_write_label;
170 }
171 else {
172 $output = $printer->_write_label . $output;
173 }
174
175 return _handle_output($printer, $output, $want_value, $_[0]);
176}
177
178
179sub _handle_output {
180 my ($printer, $output, $wantarray, $data) = @_;
181
182 if ($printer->return_value eq 'pass') {
183 print { $printer->{output_handle} } $output . "\n";
184 require Scalar::Util;
185 my $ref = Scalar::Util::blessed($data);
186 return $data if defined $ref;
187 $ref = Scalar::Util::reftype($data);
188 if (!$ref) {
189 return $data;
190 }
191 elsif ($ref eq 'ARRAY') {
192 return @$data;
193 }
194 elsif ($ref eq 'HASH') {
195 return %$data;
196 }
197 elsif ( grep { $ref eq $_ } qw(REF SCALAR VSTRING) ) {
198 return $$data;
199 }
200 else {
201 return $data;
202 }
203 }
204 elsif ($printer->return_value eq 'void' || !$wantarray) {
205 print { $printer->{output_handle} } $output . "\n";
206 return;
207 }
208 else {
209 return $output;
210 }
211}
212
213sub _fetch_args_with {
214 my ($caller, $run_properties) = @_;
215
216 my $args_to_use = {};
217 if (keys %$rc_arguments) {
218 $args_to_use = Data::Printer::Config::_merge_options(
219 $args_to_use, $rc_arguments->{'_'}
220 );
221 if (exists $rc_arguments->{$caller}) {
222 $args_to_use = Data::Printer::Config::_merge_options(
223 $args_to_use, $rc_arguments->{$caller}
224 );
225 }
226 }
227 if ($arguments_for{$caller}) {
228 $args_to_use = Data::Printer::Config::_merge_options(
229 $args_to_use, $arguments_for{$caller}
230 );
231 }
232 if (keys %$run_properties) {
233 $run_properties = Data::Printer::Config::_expand_profile($run_properties)
234 if exists $run_properties->{profile};
235 $args_to_use = Data::Printer::Config::_merge_options(
236 $args_to_use, $run_properties
237 );
238 }
239 return $args_to_use;
240}
241
242
243
# spent 3µs within Data::Printer::_find_option which was called 2 times, avg 2µs/call: # once (2µs+0s) by Data::Printer::import at line 34 # once (1µs+0s) by Data::Printer::import at line 37
sub _find_option {
2442800ns my ($key, $args, $caller, $default) = @_;
245
2462200ns my $value;
24721µs if (exists $args->{$key}) {
248 $value = $args->{$key};
249 }
250 elsif (
251 exists $rc_arguments->{$caller}
252 && exists $rc_arguments->{$caller}{$key}
253 ) {
254 $value = $rc_arguments->{$caller}{$key};
255 }
256 elsif (exists $rc_arguments->{'_'}{$key}) {
257 $value = $rc_arguments->{'_'}{$key};
258 }
259 else {
2602300ns $value = $default;
261 }
26223µs return $value;
263}
264
265
26613µs'Marielle, presente.';
267__END__