← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Wed Dec 14 16:10:05 2022
Reported on Wed Dec 14 16:12:58 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Mojo/JSON/Pointer.pm
StatementsExecuted 380420 statements in 864ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
4784611599ms950msMojo::JSON::Pointer::::_pointerMojo::JSON::Pointer::_pointer
4784632208ms1.16sMojo::JSON::Pointer::::getMojo::JSON::Pointer::get
1467083190.0ms90.0msMojo::JSON::Pointer::::CORE:substMojo::JSON::Pointer::CORE:subst (opcode)
21111889µs889µsMojo::JSON::Pointer::::CORE:matchMojo::JSON::Pointer::CORE:match (opcode)
1522101µs130µsMojo::JSON::Pointer::::newMojo::JSON::Pointer::new
11143µs199µsMojo::JSON::Pointer::::BEGIN@2Mojo::JSON::Pointer::BEGIN@2
0000s0sMojo::JSON::Pointer::::containsMojo::JSON::Pointer::contains
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Mojo::JSON::Pointer;
22369µs2355µs
# spent 199µs (43+156) within Mojo::JSON::Pointer::BEGIN@2 which was called: # once (43µs+156µs) by Moo::_Utils::_require at line 2
use Mojo::Base -base;
# spent 199µs making 1 call to Mojo::JSON::Pointer::BEGIN@2 # spent 156µs making 1 call to Mojo::Base::import
3
412µs165µshas 'data';
# spent 65µs making 1 call to Mojo::JSON::Pointer::has
5
6sub contains { shift->_pointer(0, @_) }
747846140ms47846950ms
# spent 1.16s (208ms+950ms) within Mojo::JSON::Pointer::get which was called 47846 times, avg 24µs/call: # 39123 times (178ms+716ms) by JSON::Schema::Modern::_fetch_from_uri at line 858 of JSON/Schema/Modern.pm, avg 23µs/call # 7758 times (23.5ms+155ms) by JSON::Schema::Modern::_fetch_from_uri at line 882 of JSON/Schema/Modern.pm, avg 23µs/call # 965 times (6.30ms+78.7ms) by JSON::Schema::Modern::Document::OpenAPI::traverse at line 161 of JSON/Schema/Modern/Document/OpenAPI.pm, avg 88µs/call
sub get { shift->_pointer(1, @_) }
# spent 950ms making 47846 calls to Mojo::JSON::Pointer::_pointer, avg 20µs/call
8
91573µs1529µs
# spent 130µs (101+29) within Mojo::JSON::Pointer::new which was called 15 times, avg 9µs/call: # 14 times (93µs+26µs) by JSON::Schema::Modern::Document::new at line 53 of (eval 428)[Sub/Quote.pm:3], avg 8µs/call # once (8µs+3µs) by JSON::Schema::Modern::Document::OpenAPI::new at line 56 of (eval 421)[Sub/Quote.pm:3]
sub new { @_ > 1 ? shift->SUPER::new(data => shift) : shift->SUPER::new }
# spent 29µs making 15 calls to Mojo::Base::new, avg 2µs/call
10
11
# spent 950ms (599+351) within Mojo::JSON::Pointer::_pointer which was called 47846 times, avg 20µs/call: # 47846 times (599ms+351ms) by Mojo::JSON::Pointer::get at line 7, avg 20µs/call
sub _pointer {
124784631.2ms my ($self, $get, $pointer) = @_;
13
144784695.6ms47846261ms my $data = $self->data;
# spent 261ms making 47846 calls to JSON::Schema::Modern::Document::data, avg 5µs/call
1547846236ms4784656.1ms return length $pointer ? undef : $get ? $data : 1 unless $pointer =~ s!^/!!;
# spent 56.1ms making 47846 calls to Mojo::JSON::Pointer::CORE:subst, avg 1µs/call
162036251.1ms for my $p (length $pointer ? (split /\//, $pointer, -1) : ($pointer)) {
174943192.8ms4943121.0ms $p =~ s!~1!/!g;
# spent 21.0ms making 49431 calls to Mojo::JSON::Pointer::CORE:subst, avg 424ns/call
184943175.4ms4943112.8ms $p =~ s/~0/~/g;
# spent 12.8ms making 49431 calls to Mojo::JSON::Pointer::CORE:subst, avg 260ns/call
19
20 # Hash
2149431101ms211889µs if (ref $data eq 'HASH' && exists $data->{$p}) { $data = $data->{$p} }
# spent 889µs making 211 calls to Mojo::JSON::Pointer::CORE:match, avg 4µs/call
22
23 # Array
24 elsif (ref $data eq 'ARRAY' && $p =~ /^\d+$/ && @$data > $p) { $data = $data->[$p] }
25
26 # Nothing
27 else { return undef }
28 }
29
302036240.4ms return $get ? $data : 1;
31}
32
3314µs1;
34
35=encoding utf8
36
37=head1 NAME
38
39Mojo::JSON::Pointer - JSON Pointers
40
41=head1 SYNOPSIS
42
43 use Mojo::JSON::Pointer;
44
45 my $pointer = Mojo::JSON::Pointer->new({foo => [23, 'bar']});
46 say $pointer->get('/foo/1');
47 say 'Contains "/foo".' if $pointer->contains('/foo');
48
49=head1 DESCRIPTION
50
51L<Mojo::JSON::Pointer> is an implementation of L<RFC 6901|https://tools.ietf.org/html/rfc6901>.
52
53=head1 ATTRIBUTES
54
55L<Mojo::JSON::Pointer> implements the following attributes.
56
57=head2 data
58
59 my $data = $pointer->data;
60 $pointer = $pointer->data({foo => 'bar'});
61
62Data structure to be processed.
63
64=head1 METHODS
65
66L<Mojo::JSON::Pointer> inherits all methods from L<Mojo::Base> and implements the following new ones.
67
68=head2 contains
69
70 my $bool = $pointer->contains('/foo/1');
71
72Check if L</"data"> contains a value that can be identified with the given JSON Pointer.
73
74 # True
75 Mojo::JSON::Pointer->new('just a string')->contains('');
76 Mojo::JSON::Pointer->new({'♥' => 'mojolicious'})->contains('/♥');
77 Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5]})->contains('/foo');
78 Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5]})->contains('/baz/1');
79
80 # False
81 Mojo::JSON::Pointer->new({'♥' => 'mojolicious'})->contains('/☃');
82 Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5]})->contains('/bar');
83 Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5]})->contains('/baz/9');
84
85=head2 get
86
87 my $value = $pointer->get('/foo/bar');
88
89Extract value from L</"data"> identified by the given JSON Pointer.
90
91 # "just a string"
92 Mojo::JSON::Pointer->new('just a string')->get('');
93
94 # "mojolicious"
95 Mojo::JSON::Pointer->new({'♥' => 'mojolicious'})->get('/♥');
96
97 # "bar"
98 Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5, 6]})->get('/foo');
99
100 # "4"
101 Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5, 6]})->get('/baz/0');
102
103 # "6"
104 Mojo::JSON::Pointer->new({foo => 'bar', baz => [4, 5, 6]})->get('/baz/2');
105
106=head2 new
107
108 my $pointer = Mojo::JSON::Pointer->new;
109 my $pointer = Mojo::JSON::Pointer->new({foo => 'bar'});
110
111Build new L<Mojo::JSON::Pointer> object.
112
113=head1 SEE ALSO
114
115L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
116
117=cut
 
# spent 889µs within Mojo::JSON::Pointer::CORE:match which was called 211 times, avg 4µs/call: # 211 times (889µs+0s) by Mojo::JSON::Pointer::_pointer at line 21, avg 4µs/call
sub Mojo::JSON::Pointer::CORE:match; # opcode
# spent 90.0ms within Mojo::JSON::Pointer::CORE:subst which was called 146708 times, avg 613ns/call: # 49431 times (21.0ms+0s) by Mojo::JSON::Pointer::_pointer at line 17, avg 424ns/call # 49431 times (12.8ms+0s) by Mojo::JSON::Pointer::_pointer at line 18, avg 260ns/call # 47846 times (56.1ms+0s) by Mojo::JSON::Pointer::_pointer at line 15, avg 1µs/call
sub Mojo::JSON::Pointer::CORE:subst; # opcode