← Index
NYTProf Performance Profile   « block view • line view • sub view »
For mentat.storage.mongo.pl
  Run on Tue Jun 24 10:04:38 2014
Reported on Tue Jun 24 10:05:13 2014

Filename/usr/share/perl/5.14/bigint.pm
StatementsExecuted 349 statements in 2.26ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
99115.1ms28.0msbigint::::importbigint::import
11119µs19µsbigint::::BEGIN@2bigint::BEGIN@2
11111µs22µsbigint::::BEGIN@269bigint::BEGIN@269
1119µs27µsbigint::::BEGIN@5bigint::BEGIN@5
1118µs11µsbigint::::BEGIN@10bigint::BEGIN@10
1117µs19µsbigint::::BEGIN@275bigint::BEGIN@275
1117µs30µsbigint::::BEGIN@11bigint::BEGIN@11
1117µs18µsbigint::::BEGIN@25bigint::BEGIN@25
1116µs41µsbigint::::BEGIN@18bigint::BEGIN@18
1116µs15µsbigint::::BEGIN@33bigint::BEGIN@33
0000s0sbigint::::AUTOLOADbigint::AUTOLOAD
0000s0sbigint::::NaNbigint::NaN
0000s0sbigint::::PIbigint::PI
0000s0sbigint::::__ANON__[:262]bigint::__ANON__[:262]
0000s0sbigint::::__ANON__[:264]bigint::__ANON__[:264]
0000s0sbigint::::__ANON__[:39]bigint::__ANON__[:39]
0000s0sbigint::::_binary_constantbigint::_binary_constant
0000s0sbigint::::_float_constantbigint::_float_constant
0000s0sbigint::::_hexbigint::_hex
0000s0sbigint::::_hex_globalbigint::_hex_global
0000s0sbigint::::_octbigint::_oct
0000s0sbigint::::_oct_globalbigint::_oct_global
0000s0sbigint::::bexpbigint::bexp
0000s0sbigint::::bpibigint::bpi
0000s0sbigint::::ebigint::e
0000s0sbigint::::in_effectbigint::in_effect
0000s0sbigint::::infbigint::inf
0000s0sbigint::::unimportbigint::unimport
0000s0sbigint::::upgradebigint::upgrade
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package bigint;
2249µs119µs
# spent 19µs within bigint::BEGIN@2 which was called: # once (19µs+0s) by Value::Convertor::BEGIN@364 at line 2
use 5.006;
# spent 19µs making 1 call to bigint::BEGIN@2
3
41500ns$VERSION = '0.27';
5254µs246µs
# spent 27µs (9+18) within bigint::BEGIN@5 which was called: # once (9µs+18µs) by Value::Convertor::BEGIN@364 at line 5
use Exporter;
# spent 27µs making 1 call to bigint::BEGIN@5 # spent 18µs making 1 call to Exporter::import
616µs@ISA = qw( Exporter );
711µs@EXPORT_OK = qw( PI e bpi bexp );
81500ns@EXPORT = qw( inf NaN );
9
10220µs214µs
# spent 11µs (8+3) within bigint::BEGIN@10 which was called: # once (8µs+3µs) by Value::Convertor::BEGIN@364 at line 10
use strict;
# spent 11µs making 1 call to bigint::BEGIN@10 # spent 3µs making 1 call to strict::import
11236µs253µs
# spent 30µs (7+23) within bigint::BEGIN@11 which was called: # once (7µs+23µs) by Value::Convertor::BEGIN@364 at line 11
use overload;
# spent 30µs making 1 call to bigint::BEGIN@11 # spent 23µs making 1 call to overload::import
12
13##############################################################################
14
15# These are all alike, and thus faked by AUTOLOAD
16
171900nsmy @faked = qw/round_mode accuracy precision div_scale/;
18248µs276µs
# spent 41µs (6+35) within bigint::BEGIN@18 which was called: # once (6µs+35µs) by Value::Convertor::BEGIN@364 at line 18
use vars qw/$VERSION $AUTOLOAD $_lite/; # _lite for testsuite
# spent 41µs making 1 call to bigint::BEGIN@18 # spent 35µs making 1 call to vars::import
19
20sub AUTOLOAD
21 {
22 my $name = $AUTOLOAD;
23
24 $name =~ s/.*:://; # split package
25252µs228µs
# spent 18µs (7+11) within bigint::BEGIN@25 which was called: # once (7µs+11µs) by Value::Convertor::BEGIN@364 at line 25
no strict 'refs';
# spent 18µs making 1 call to bigint::BEGIN@25 # spent 11µs making 1 call to strict::unimport
26 foreach my $n (@faked)
27 {
28 if ($n eq $name)
29 {
30 *{"bigint::$name"} = sub
31 {
32 my $self = shift;
3321.21ms224µs
# spent 15µs (6+9) within bigint::BEGIN@33 which was called: # once (6µs+9µs) by Value::Convertor::BEGIN@364 at line 33
no strict 'refs';
# spent 15µs making 1 call to bigint::BEGIN@33 # spent 9µs making 1 call to strict::unimport
34 if (defined $_[0])
35 {
36 return Math::BigInt->$name($_[0]);
37 }
38 return Math::BigInt->$name();
39 };
40 return &$name;
41 }
42 }
43
44 # delayed load of Carp and avoid recursion
45 require Carp;
46 Carp::croak ("Can't call bigint\-\>$name, not a valid method");
47 }
48
49sub upgrade
50 {
51 $Math::BigInt::upgrade;
52 }
53
54sub _binary_constant
55 {
56 # this takes a binary/hexadecimal/octal constant string and returns it
57 # as string suitable for new. Basically it converts octal to decimal, and
58 # passes every thing else unmodified back.
59 my $string = shift;
60
61 return Math::BigInt->new($string) if $string =~ /^0[bx]/;
62
63 # so it must be an octal constant
64 Math::BigInt->from_oct($string);
65 }
66
67sub _float_constant
68 {
69 # this takes a floating point constant string and returns it truncated to
70 # integer. For instance, '4.5' => '4', '1.234e2' => '123' etc
71 my $float = shift;
72
73 # some simple cases first
74 return $float if ($float =~ /^[+-]?[0-9]+$/); # '+123','-1','0' etc
75 return $float
76 if ($float =~ /^[+-]?[0-9]+\.?[eE]\+?[0-9]+$/); # 123e2, 123.e+2
77 return '0' if ($float =~ /^[+-]?[0]*\.[0-9]+$/); # .2, 0.2, -.1
78 if ($float =~ /^[+-]?[0-9]+\.[0-9]*$/) # 1., 1.23, -1.2 etc
79 {
80 $float =~ s/\..*//;
81 return $float;
82 }
83 my ($mis,$miv,$mfv,$es,$ev) = Math::BigInt::_split($float);
84 return $float if !defined $mis; # doesn't look like a number to me
85 my $ec = int($$ev);
86 my $sign = $$mis; $sign = '' if $sign eq '+';
87 if ($$es eq '-')
88 {
89 # ignore fraction part entirely
90 if ($ec >= length($$miv)) # 123.23E-4
91 {
92 return '0';
93 }
94 return $sign . substr ($$miv,0,length($$miv)-$ec); # 1234.45E-2 = 12
95 }
96 # xE+y
97 if ($ec >= length($$mfv))
98 {
99 $ec -= length($$mfv);
100 return $sign.$$miv.$$mfv if $ec == 0; # 123.45E+2 => 12345
101 return $sign.$$miv.$$mfv.'E'.$ec; # 123.45e+3 => 12345e1
102 }
103 $mfv = substr($$mfv,0,$ec);
104 $sign.$$miv.$mfv; # 123.45e+1 => 1234
105 }
106
107sub unimport
108 {
109 $^H{bigint} = undef; # no longer in effect
110 overload::remove_constant('binary','','float','','integer');
111 }
112
113sub in_effect
114 {
115 my $level = shift || 0;
116 my $hinthash = (caller($level))[10];
117 $hinthash->{bigint};
118 }
119
120#############################################################################
121# the following two routines are for "use bigint qw/hex oct/;":
122
123sub _hex_global
124 {
125 my $i = $_[0];
126 $i = '0x'.$i unless $i =~ /^0x/;
127 Math::BigInt->new($i);
128 }
129
130sub _oct_global
131 {
132 my $i = $_[0];
133 return Math::BigInt->from_oct($i) if $i =~ /^0[0-7]/;
134 Math::BigInt->new($i);
135 }
136
137#############################################################################
138# the following two routines are for Perl 5.9.4 or later and are lexical
139
140sub _hex
141 {
142 return CORE::hex($_[0]) unless in_effect(1);
143 my $i = $_[0];
144 $i = '0x'.$i unless $i =~ /^0x/;
145 Math::BigInt->new($i);
146 }
147
148sub _oct
149 {
150 return CORE::oct($_[0]) unless in_effect(1);
151 my $i = $_[0];
152 return Math::BigInt->from_oct($i) if $i =~ /^0[0-7]/;
153 Math::BigInt->new($i);
154 }
155
156sub import
157
# spent 28.0ms (15.1+12.9) within bigint::import which was called 9 times, avg 3.11ms/call: # once (14.5ms+11.0ms) by Value::Convertor::BEGIN@364 at line 364 of Value/Convertor.pm # once (84µs+268µs) by Value::Convertor::BEGIN@1230 at line 1230 of Value/Convertor.pm # once (79µs+249µs) by Value::Convertor::BEGIN@1801 at line 1801 of Value/Convertor.pm # once (83µs+246µs) by Value::Convertor::BEGIN@2068 at line 2068 of Value/Convertor.pm # once (81µs+245µs) by Value::Convertor::BEGIN@1721 at line 1721 of Value/Convertor.pm # once (79µs+244µs) by Value::Convertor::BEGIN@389 at line 389 of Value/Convertor.pm # once (82µs+238µs) by Value::Convertor::BEGIN@1746 at line 1746 of Value/Convertor.pm # once (81µs+239µs) by Value::Convertor::BEGIN@1774 at line 1774 of Value/Convertor.pm # once (76µs+238µs) by Value::Convertor::BEGIN@2047 at line 2047 of Value/Convertor.pm
{
158234201µs my $self = shift;
159
160 $^H{bigint} = 1; # we are in effect
161
162 my ($hex,$oct);
163 # for newer Perls always override hex() and oct() with a lexical version:
164189µs if ($] > 5.009004)
165 {
166 $oct = \&_oct;
167 $hex = \&_hex;
168 }
169 # some defaults
170 my $lib = ''; my $lib_kind = 'try';
171
172 my @import = ( ':constant' ); # drive it w/ constant
173 my @a = @_; my $l = scalar @_; my $j = 0;
174 my ($ver,$trace); # version? trace?
175 my ($a,$p); # accuracy, precision
176 for ( my $i = 0; $i < $l ; $i++,$j++ )
177 {
178 if ($_[$i] =~ /^(l|lib|try|only)$/)
179 {
180 # this causes a different low lib to take care...
181 $lib_kind = $1; $lib_kind = 'lib' if $lib_kind eq 'l';
182 $lib = $_[$i+1] || '';
183 my $s = 2; $s = 1 if @a-$j < 2; # avoid "can not modify non-existent..."
184 splice @a, $j, $s; $j -= $s; $i++;
185 }
186 elsif ($_[$i] =~ /^(a|accuracy)$/)
187 {
188 $a = $_[$i+1];
189 my $s = 2; $s = 1 if @a-$j < 2; # avoid "can not modify non-existent..."
190 splice @a, $j, $s; $j -= $s; $i++;
191 }
192 elsif ($_[$i] =~ /^(p|precision)$/)
193 {
194 $p = $_[$i+1];
195 my $s = 2; $s = 1 if @a-$j < 2; # avoid "can not modify non-existent..."
196 splice @a, $j, $s; $j -= $s; $i++;
197 }
198 elsif ($_[$i] =~ /^(v|version)$/)
199 {
200 $ver = 1;
201 splice @a, $j, 1; $j --;
202 }
203 elsif ($_[$i] =~ /^(t|trace)$/)
204 {
205 $trace = 1;
206 splice @a, $j, 1; $j --;
207 }
208 elsif ($_[$i] eq 'hex')
209 {
210 splice @a, $j, 1; $j --;
211 $hex = \&_hex_global;
212 }
213 elsif ($_[$i] eq 'oct')
214 {
215 splice @a, $j, 1; $j --;
216 $oct = \&_oct_global;
217 }
218 elsif ($_[$i] !~ /^(PI|e|bpi|bexp)\z/)
219 {
220 die ("unknown option $_[$i]");
221 }
222 }
223 my $class;
224 $_lite = 0; # using M::BI::L ?
22527104µs if ($trace)
226 {
227 require Math::BigInt::Trace; $class = 'Math::BigInt::Trace';
228 }
229 else
230 {
231 # see if we can find Math::BigInt::Lite
23218182µs if (!defined $a && !defined $p) # rounding won't work to well
233 {
234 eval 'require Math::BigInt::Lite;';
# spent 313µs executing statements in 9 string evals (merged)
235 if ($@ eq '')
236 {
237 @import = ( ); # :constant in Lite, not MBI
238 Math::BigInt::Lite->import( ':constant' );
239 $_lite= 1; # signal okay
240 }
241 }
242 require Math::BigInt if $_lite == 0; # not already loaded?
243 $class = 'Math::BigInt'; # regardless of MBIL or not
244 }
245 push @import, $lib_kind => $lib if $lib ne '';
246 # Math::BigInt::Trace or plain Math::BigInt
247911.6ms $class->import(@import);
# spent 11.6ms making 9 calls to Math::BigInt::import, avg 1.29ms/call
248
249 bigint->accuracy($a) if defined $a;
250 bigint->precision($p) if defined $p;
251 if ($ver)
252 {
253 print "bigint\t\t\t v$VERSION\n";
254 print "Math::BigInt::Lite\t v$Math::BigInt::Lite::VERSION\n" if $_lite;
255 print "Math::BigInt\t\t v$Math::BigInt::VERSION";
256 my $config = Math::BigInt->config();
257 print " lib => $config->{lib} v$config->{lib_version}\n";
258 exit;
259 }
260 # we take care of floating point constants, since BigFloat isn't available
261 # and BigInt doesn't like them:
2629105µs overload::constant float => sub { Math::BigInt->new( _float_constant(shift) ); };
# spent 105µs making 9 calls to overload::constant, avg 12µs/call
263 # Take care of octal/hexadecimal constants
264974µs overload::constant binary => sub { _binary_constant(shift) };
# spent 74µs making 9 calls to overload::constant, avg 8µs/call
265
266 # if another big* was already loaded:
267 my ($package) = caller();
268
269250µs233µs
# spent 22µs (11+11) within bigint::BEGIN@269 which was called: # once (11µs+11µs) by Value::Convertor::BEGIN@364 at line 269
no strict 'refs';
# spent 22µs making 1 call to bigint::BEGIN@269 # spent 11µs making 1 call to strict::unimport
270109µs if (!defined *{"${package}::inf"})
271 {
272120µs $self->export_to_level(1,$self,@a); # export inf and NaN, e and PI
# spent 20µs making 1 call to Exporter::export_to_level
273 }
274 {
2752204µs231µs
# spent 19µs (7+12) within bigint::BEGIN@275 which was called: # once (7µs+12µs) by Value::Convertor::BEGIN@364 at line 275
no warnings 'redefine';
# spent 19µs making 1 call to bigint::BEGIN@275 # spent 12µs making 1 call to warnings::unimport
2761817µs *CORE::GLOBAL::oct = $oct if $oct;
277 *CORE::GLOBAL::hex = $hex if $hex;
278 }
279 }
280
281sub inf () { Math::BigInt::binf(); }
282sub NaN () { Math::BigInt::bnan(); }
283
284sub PI () { Math::BigInt->new(3); }
285sub e () { Math::BigInt->new(2); }
286sub bpi ($) { Math::BigInt->new(3); }
287sub bexp ($$) { my $x = Math::BigInt->new($_[0]); $x->bexp($_[1]); }
288
28916µs1;
290
291__END__