2009/7/18 Octavian Râşniţă <[email protected]>:
> From: "Dr.Ruud" <[email protected]>
>>
>> To me that means that you "don't get it" yet.
>
> Oh yes I get it, but I don't like it.
>
> What would be the problem if the way of doing calculations by using bignum
> would be the default?
> Does it give errors? It would be helpful to know.
>
> Octavian
Because it is slower. If you want to use bignums by default you can use the
[bignum][0] pragma, but be warned, there is a massive performance penalty:
normal => 500500
bignum => 500500
Rate bignum normal
bignum 19.0/s -- -100%
normal 7587/s 39733% --
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark;
my @a = 1 .. 1_000;
my %subs = (
normal => sub { my $r = 0; $r += $_ for @a; return $r },
bignum => sub { use bignum; my $r = 0; $r += $_ for @a; return $r },
);
for my $sub (keys %subs) {
print "$sub => ", $subs{$sub}->(), "\n";
}
Benchmark::cmpthese -1, \%subs;
[0] : http://perldoc.perl.org/bignum.html
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/