← 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/Search/Elasticsearch/Role/Serializer/JSON.pm
StatementsExecuted 9020 statements in 74.3ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
10011121.2ms90.3msSearch::Elasticsearch::Role::Serializer::JSON::::decodeSearch::Elasticsearch::Role::Serializer::JSON::decode
20011116.2ms34.1msSearch::Elasticsearch::Role::Serializer::JSON::::try {...} Search::Elasticsearch::Role::Serializer::JSON::try {...}
1000119.31ms50.6msSearch::Elasticsearch::Role::Serializer::JSON::::encodeSearch::Elasticsearch::Role::Serializer::JSON::encode
1001111.04ms1.04msSearch::Elasticsearch::Role::Serializer::JSON::::CORE:matchSearch::Elasticsearch::Role::Serializer::JSON::CORE:match (opcode)
1118µs668µsSearch::Elasticsearch::Role::Serializer::JSON::::BEGIN@3Search::Elasticsearch::Role::Serializer::JSON::BEGIN@3
1116µs30µsSearch::Elasticsearch::Role::Serializer::JSON::::BEGIN@7Search::Elasticsearch::Role::Serializer::JSON::BEGIN@7
1115µs109µsSearch::Elasticsearch::Role::Serializer::JSON::::BEGIN@6Search::Elasticsearch::Role::Serializer::JSON::BEGIN@6
1115µs22µsSearch::Elasticsearch::Role::Serializer::JSON::::BEGIN@8Search::Elasticsearch::Role::Serializer::JSON::BEGIN@8
1114µs140µsSearch::Elasticsearch::Role::Serializer::JSON::::BEGIN@9Search::Elasticsearch::Role::Serializer::JSON::BEGIN@9
111600ns600nsSearch::Elasticsearch::Role::Serializer::JSON::::mime_typeSearch::Elasticsearch::Role::Serializer::JSON::mime_type (xsub)
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:24]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:24]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:25]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:25]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:46]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:46]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:47]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:47]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:59]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:59]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:62]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:62]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:65]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:65]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:82]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:82]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::__ANON__[:85]Search::Elasticsearch::Role::Serializer::JSON::__ANON__[:85]
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::_set_canonicalSearch::Elasticsearch::Role::Serializer::JSON::_set_canonical
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::catch {...} Search::Elasticsearch::Role::Serializer::JSON::catch {...}
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::encode_bulkSearch::Elasticsearch::Role::Serializer::JSON::encode_bulk
0000s0sSearch::Elasticsearch::Role::Serializer::JSON::::encode_prettySearch::Elasticsearch::Role::Serializer::JSON::encode_pretty
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Search::Elasticsearch::Role::Serializer::JSON;
21200ns$Search::Elasticsearch::Role::Serializer::JSON::VERSION = '5.01';
3226µs21.33ms
# spent 668µs (8+660) within Search::Elasticsearch::Role::Serializer::JSON::BEGIN@3 which was called: # once (8µs+660µs) by Module::Runtime::require_module at line 3
use Moo::Role;
# spent 668µs making 1 call to Search::Elasticsearch::Role::Serializer::JSON::BEGIN@3 # spent 660µs making 1 call to Moo::Role::import
41900ns110µsrequires 'JSON';
# spent 10µs making 1 call to Moo::Role::requires
5
6220µs2213µs
# spent 109µs (5+104) within Search::Elasticsearch::Role::Serializer::JSON::BEGIN@6 which was called: # once (5µs+104µs) by Module::Runtime::require_module at line 6
use Search::Elasticsearch::Util qw(throw);
7218µs254µs
# spent 30µs (6+24) within Search::Elasticsearch::Role::Serializer::JSON::BEGIN@7 which was called: # once (6µs+24µs) by Module::Runtime::require_module at line 7
use Try::Tiny;
# spent 30µs making 1 call to Search::Elasticsearch::Role::Serializer::JSON::BEGIN@7 # spent 24µs making 1 call to Exporter::import
8214µs240µs
# spent 22µs (5+18) within Search::Elasticsearch::Role::Serializer::JSON::BEGIN@8 which was called: # once (5µs+18µs) by Module::Runtime::require_module at line 8
use Encode qw(encode_utf8 decode_utf8 is_utf8);
# spent 22µs making 1 call to Search::Elasticsearch::Role::Serializer::JSON::BEGIN@8 # spent 18µs making 1 call to Exporter::import
92373µs2276µs
# spent 140µs (4+136) within Search::Elasticsearch::Role::Serializer::JSON::BEGIN@9 which was called: # once (4µs+136µs) by Module::Runtime::require_module at line 9
use namespace::clean;
# spent 140µs making 1 call to Search::Elasticsearch::Role::Serializer::JSON::BEGIN@9 # spent 136µs making 1 call to namespace::clean::import
10
111900ns1115µshas 'mime_type' => ( is => 'ro', default => 'application/json' );
# spent 115µs making 1 call to Moo::Role::has
12
131700ns1820µswith 'Search::Elasticsearch::Role::Serializer';
# spent 820µs making 1 call to Moo::Role::with
14
15#===================================
16
# spent 50.6ms (9.31+41.3) within Search::Elasticsearch::Role::Serializer::JSON::encode which was called 1000 times, avg 51µs/call: # 1000 times (9.31ms+41.3ms) by Search::Elasticsearch::Role::Transport::tidy_request at line 39 of Search/Elasticsearch/Role/Transport.pm, avg 51µs/call
sub encode {
17#===================================
181000560µs my ( $self, $var ) = @_;
191000516µs unless ( ref $var ) {
20 return is_utf8($var)
21 ? encode_utf8($var)
22 : $var;
23 }
24100019.1ms10017.02ms return try { $self->JSON->encode($var) }
# spent 7.02ms making 1000 calls to Cpanel::JSON::XS::encode, avg 7µs/call # spent 800ns making 1 call to BenchmarkAnything::Storage::Search::Elasticsearch::Serializer::JSON::DontTouchMyUTF8::JSON
25100013.3ms200041.3ms catch { throw( "Serializer", $_, { var => $var } ) };
# spent 31.9ms making 1000 calls to Try::Tiny::try, avg 32µs/call # spent 9.39ms making 1000 calls to Try::Tiny::catch, avg 9µs/call
26}
27
28#===================================
29sub encode_bulk {
30#===================================
31 my ( $self, $var ) = @_;
32 unless ( ref $var ) {
33 return is_utf8($var)
34 ? encode_utf8($var)
35 : $var;
36 }
37
38 my $json = '';
39 throw( "Param", "Var must be an array ref" )
40 unless ref $var eq 'ARRAY';
41 return try {
42 for (@$var) {
43 $json .= ( ref($_) ? $self->JSON->encode($_) : $_ ) . "\n";
44 }
45 return $json;
46 }
47 catch { throw( "Serializer", $_, { var => $var } ) };
48}
49
50#===================================
51sub encode_pretty {
52#===================================
53 my ( $self, $var ) = @_;
54 $self->JSON->pretty(1);
55
56 my $json;
57 try {
58 $json = $self->encode($var);
59 }
60 catch {
61 die "$_";
62 }
63 finally {
64 $self->JSON->pretty(0);
65 };
66
67 return $json;
68}
69
70#===================================
71
# spent 90.3ms (21.2+69.1) within Search::Elasticsearch::Role::Serializer::JSON::decode which was called 1001 times, avg 90µs/call: # 1001 times (21.2ms+69.1ms) by Search::Elasticsearch::Role::Cxn::process_response at line 314 of Search/Elasticsearch/Role/Cxn.pm, avg 90µs/call
sub decode {
72#===================================
731001671µs my ( $self, $json ) = @_;
74
751001432µs return unless defined $json;
76
77100110.4ms10011.04ms return is_utf8($json) ? $json : decode_utf8($json)
# spent 1.04ms making 1001 calls to Search::Elasticsearch::Role::Serializer::JSON::CORE:match, avg 1µs/call
78 unless substr( $json, 0, 1 ) =~ /^[\[{]/;
79
80
# spent 34.1ms (16.2+17.9) within Search::Elasticsearch::Role::Serializer::JSON::try {...} which was called 2001 times, avg 17µs/call: # 2001 times (16.2ms+17.9ms) by Try::Tiny::try at line 87 of Try/Tiny.pm, avg 17µs/call
return try {
81100118.2ms100210.9ms $self->JSON->decode($json);
# spent 10.9ms making 1001 calls to Cpanel::JSON::XS::decode, avg 11µs/call # spent 1µs making 1 call to BenchmarkAnything::Storage::Search::Elasticsearch::Serializer::JSON::DontTouchMyUTF8::JSON
82 }
83 catch {
84 throw( "Serializer", $_, { json => $json } );
85100110.7ms200225.1ms };
# spent 25.1ms making 1001 calls to Try::Tiny::catch, avg 25µs/call # spent 43.0ms making 1001 calls to Try::Tiny::try, avg 43µs/call, recursion: max depth 1, sum of overlapping time 43.0ms
86}
87
88#===================================
89sub _set_canonical {
90#===================================
91 shift()->JSON->canonical(1);
92}
93
9414µs1;
95
96=pod
97
98=encoding UTF-8
99
100=head1 NAME
101
102Search::Elasticsearch::Role::Serializer::JSON - A Serializer role for JSON modules
103
104=head1 VERSION
105
106version 5.01
107
108=head1 DESCRIPTION
109
110This role encodes Perl data structures into JSON strings, and
111decodes JSON strings into Perl data structures.
112
113=head1 METHODS
114
115=head2 C<encode()>
116
117 $bytes = $serializer->encode($ref);
118 $bytes = $serializer->encode($str);
119
120The L</encode()> method converts array and hash refs into their JSON
121equivalents. If a string is passed in, it is returned as the UTF8 encoded
122version of itself. The empty string and C<undef> are returned as is.
123
124=head2 C<encode_pretty()>
125
126 $bytes = $serializer->encode_pretty($ref);
127 $bytes = $serializer->encode_pretty($str);
128
129Works exactly as L</encode()> but the JSON output is pretty-printed.
130
131=head2 C<encode_bulk()>
132
133 $bytes = $serializer->encode_bulk([\%hash,\%hash,...]);
134 $bytes = $serializer->encode_bulk([$str,$str,...]);
135
136The L</encode_bulk()> method expects an array ref of hashes or strings.
137Each hash or string is processed by L</encode()> then joined together
138by newline characters, with a final newline character appended to the end.
139This is the special JSON format used for bulk requests.
140
141=head2 C<decode()>
142
143 $var = $serializer->decode($json_bytes);
144 $str = $serializer->decode($bytes);
145
146If the passed in value looks like JSON (ie starts with a C<{> or C<[>
147character), then it is decoded from JSON, otherwise it is returned as
148the UTF8 decoded version of itself. The empty string and C<undef> are
149returned as is.
150
151=head1 AUTHOR
152
153Clinton Gormley <drtech@cpan.org>
154
155=head1 COPYRIGHT AND LICENSE
156
157This software is Copyright (c) 2016 by Elasticsearch BV.
158
159This is free software, licensed under:
160
161 The Apache License, Version 2.0, January 2004
162
163=cut
164
16518µs1244µs__END__
 
# spent 1.04ms within Search::Elasticsearch::Role::Serializer::JSON::CORE:match which was called 1001 times, avg 1µs/call: # 1001 times (1.04ms+0s) by Search::Elasticsearch::Role::Serializer::JSON::decode at line 77, avg 1µs/call
sub Search::Elasticsearch::Role::Serializer::JSON::CORE:match; # opcode
# spent 600ns within Search::Elasticsearch::Role::Serializer::JSON::mime_type which was called: # once (600ns+0s) by Search::Elasticsearch::Role::Transport::tidy_request at line 54 of Search/Elasticsearch/Role/Transport.pm
sub Search::Elasticsearch::Role::Serializer::JSON::mime_type; # xsub