← Index
NYTProf Performance Profile   « block view • line view • sub view »
For mentat.storage.mongo.pl
  Run on Tue Jun 24 09:58:41 2014
Reported on Tue Jun 24 09:59:31 2014

Filename/usr/share/perl/5.14/bigint.pm
StatementsExecuted 349 statements in 4.76ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
99133.2ms60.6msbigint::::importbigint::import
11143µs43µsbigint::::BEGIN@2bigint::BEGIN@2
11124µs50µsbigint::::BEGIN@269bigint::BEGIN@269
11120µs60µsbigint::::BEGIN@5bigint::BEGIN@5
11118µs24µsbigint::::BEGIN@10bigint::BEGIN@10
11117µs38µsbigint::::BEGIN@275bigint::BEGIN@275
11115µs61µsbigint::::BEGIN@11bigint::BEGIN@11
11115µs97µsbigint::::BEGIN@18bigint::BEGIN@18
11115µs38µsbigint::::BEGIN@25bigint::BEGIN@25
11114µs33µ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;
22114µs143µs
# spent 43µs within bigint::BEGIN@2 which was called: # once (43µs+0s) by Value::Convertor::BEGIN@364 at line 2
use 5.006;
# spent 43µs making 1 call to bigint::BEGIN@2
3
412µs$VERSION = '0.27';
52120µs299µs
# spent 60µs (20+40) within bigint::BEGIN@5 which was called: # once (20µs+40µs) by Value::Convertor::BEGIN@364 at line 5
use Exporter;
# spent 60µs making 1 call to bigint::BEGIN@5 # spent 40µs making 1 call to Exporter::import
6113µs@ISA = qw( Exporter );
712µs@EXPORT_OK = qw( PI e bpi bexp );
811µs@EXPORT = qw( inf NaN );
9
10248µs231µs
# spent 24µs (18+7) within bigint::BEGIN@10 which was called: # once (18µs+7µs) by Value::Convertor::BEGIN@364 at line 10
use strict;
# spent 24µs making 1 call to bigint::BEGIN@10 # spent 7µs making 1 call to strict::import
11283µs2106µs
# spent 61µs (15+45) within bigint::BEGIN@11 which was called: # once (15µs+45µs) by Value::Convertor::BEGIN@364 at line 11
use overload;
# spent 61µs making 1 call to bigint::BEGIN@11 # spent 45µs making 1 call to overload::import
12
13##############################################################################
14
15# These are all alike, and thus faked by AUTOLOAD
16
1712µsmy @faked = qw/round_mode accuracy precision div_scale/;
182111µs2180µs
# spent 97µs (15+82) within bigint::BEGIN@18 which was called: # once (15µs+82µs) by Value::Convertor::BEGIN@364 at line 18
use vars qw/$VERSION $AUTOLOAD $_lite/; # _lite for testsuite
# spent 97µs making 1 call to bigint::BEGIN@18 # spent 82µs making 1 call to vars::import
19
20sub AUTOLOAD
21 {
22 my $name = $AUTOLOAD;
23
24 $name =~ s/.*:://; # split package
252110µs262µs
# spent 38µs (15+24) within bigint::BEGIN@25 which was called: # once (15µs+24µs) by Value::Convertor::BEGIN@364 at line 25
no strict 'refs';
# spent 38µs making 1 call to bigint::BEGIN@25 # spent 24µ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;
3322.71ms252µs
# spent 33µs (14+19) within bigint::BEGIN@33 which was called: # once (14µs+19µs) by Value::Convertor::BEGIN@364 at line 33
no strict 'refs';
# spent 33µs making 1 call to bigint::BEGIN@33 # spent 19µ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 60.6ms (33.2+27.3) within bigint::import which was called 9 times, avg 6.73ms/call: # once (32.4ms+24.4ms) by Value::Convertor::BEGIN@364 at line 364 of Value/Convertor.pm # once (173µs+603µs) by Value::Convertor::BEGIN@1230 at line 1230 of Value/Convertor.pm # once (178µs+572µs) by Value::Convertor::BEGIN@389 at line 389 of Value/Convertor.pm # once (151µs+493µs) by Value::Convertor::BEGIN@1721 at line 1721 of Value/Convertor.pm # once (72µs+281µs) by Value::Convertor::BEGIN@1801 at line 1801 of Value/Convertor.pm # once (74µs+244µs) by Value::Convertor::BEGIN@2068 at line 2068 of Value/Convertor.pm # once (73µs+241µs) by Value::Convertor::BEGIN@1774 at line 1774 of Value/Convertor.pm # once (72µs+237µs) by Value::Convertor::BEGIN@1746 at line 1746 of Value/Convertor.pm # once (68µs+236µs) by Value::Convertor::BEGIN@2047 at line 2047 of Value/Convertor.pm
{
15897µs my $self = shift;
159
160935µs $^H{bigint} = 1; # we are in effect
161
16294µs my ($hex,$oct);
163 # for newer Perls always override hex() and oct() with a lexical version:
16499µs if ($] > 5.009004)
165 {
16699µs $oct = \&_oct;
16795µs $hex = \&_hex;
168 }
169 # some defaults
170185µs my $lib = ''; my $lib_kind = 'try';
171
172911µs my @import = ( ':constant' ); # drive it w/ constant
1732710µs my @a = @_; my $l = scalar @_; my $j = 0;
17492µs my ($ver,$trace); # version? trace?
17592µs my ($a,$p); # accuracy, precision
176910µs 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 }
22392µs my $class;
22493µs $_lite = 0; # using M::BI::L ?
22594µ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
23296µs if (!defined $a && !defined $p) # rounding won't work to well
233 {
2349268µs eval 'require Math::BigInt::Lite;';
# spent 397µs executing statements in 9 string evals (merged)
23597µs if ($@ eq '')
236 {
237 @import = ( ); # :constant in Lite, not MBI
238 Math::BigInt::Lite->import( ':constant' );
239 $_lite= 1; # signal okay
240 }
241 }
2429190µs require Math::BigInt if $_lite == 0; # not already loaded?
24394µs $class = 'Math::BigInt'; # regardless of MBIL or not
244 }
24593µs push @import, $lib_kind => $lib if $lib ne '';
246 # Math::BigInt::Trace or plain Math::BigInt
247931µs924.7ms $class->import(@import);
# spent 24.7ms making 9 calls to Math::BigInt::import, avg 2.75ms/call
248
24992µs bigint->accuracy($a) if defined $a;
25091µs bigint->precision($p) if defined $p;
25192µs 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:
262946µs9156µs overload::constant float => sub { Math::BigInt->new( _float_constant(shift) ); };
# spent 156µs making 9 calls to overload::constant, avg 17µs/call
263 # Take care of octal/hexadecimal constants
264933µs9111µs overload::constant binary => sub { _binary_constant(shift) };
# spent 111µs making 9 calls to overload::constant, avg 12µs/call
265
266 # if another big* was already loaded:
267920µs my ($package) = caller();
268
2692118µs276µs
# spent 50µs (24+26) within bigint::BEGIN@269 which was called: # once (24µs+26µs) by Value::Convertor::BEGIN@364 at line 269
no strict 'refs';
# spent 50µs making 1 call to bigint::BEGIN@269 # spent 26µs making 1 call to strict::unimport
2701820µs if (!defined *{"${package}::inf"})
271 {
27219µs134µs $self->export_to_level(1,$self,@a); # export inf and NaN, e and PI
# spent 34µs making 1 call to Exporter::export_to_level
273 }
274 {
27511515µs258µs
# spent 38µs (17+20) within bigint::BEGIN@275 which was called: # once (17µs+20µs) by Value::Convertor::BEGIN@364 at line 275
no warnings 'redefine';
# spent 38µs making 1 call to bigint::BEGIN@275 # spent 20µs making 1 call to warnings::unimport
27697µs *CORE::GLOBAL::oct = $oct if $oct;
277931µs *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
289113µs1;
290
291__END__