|
Posted by ofer on February 15, 2006, 9:34 am
Please log in for more thread options
Tassilo v. Parseval wrote:
> Also sprach ofer@ilunix.org:
>
> > I don't know what exactly the problem is with this module.
>
> It's broken beyond repair.
>
> > But watch this:
> > 1st program:
> > ---------------------------------------------------------
> > #!/usr/bin/perl
> >
> > use warnings;
> > use strict;
> > use Math::Prime::XS qw( is_prime );
> >
> > die( 'please specify a number' ) unless ( @ARGV == 1 );
> >
> > my $num = $ARGV[0];
> >
> > if ( is_prime( $num ) ) {
> > print "$num is prime.\n";
> > } else {
> > print "$num is not prime.\n";
> > }
>
> > ofer@nettux:~/scripts/prime_numbers$ time ./prime_using_xs.pl 1234567
> > Segmentation fault
> >
> > real 0m0.015s
> > user 0m0.012s
> > sys 0m0.004s
>
> > Anybody knows what is wrong with Math::Prime::XS?
>
> The module is doing extremely stupid things. Here's something funny from
> its PODs:
>
> [ some benchmarks ]
>
> Bear in mind, that these results are not too reliable as the author
> could neither increase the number nor the iteration count provided,
> because if he attempted to do so, perl would report "Out of
> memory!", which was most likely caused by the Sieve of Eratosthenes
> algorithm, which is rather memory exhaustive by implementation.
>
> No, it's not caused at all by that but rather by this:
>
> void
> xs_is_prime(number)
> long number
> PROTOTYPE: $
> INIT:
> long primes[number], psum[number];
> long i, n, pcount, square_root;
> bool is_prime;
>
> For your input of 1234567, this will try to create two arrays 'primes'
> and 'psum' of longs, each 1234567 elements long on the stack! This
> hurts.
>
> And if the author of that package isn't able to come up with an
> implementation of the Sieve of Eratosthenes that gets away with only a
> few megabytes at most, then he is not to be trusted.
>
> With the exception of mod_primes, all functions in that module behave
> abnormally with respect to runtime and memory consumption. I'd stay away
> from that module.
>
> Tassilo
> --
> use bigint;
> $n=71423350343770280161397026330337371139054411854220053437565440;
> $m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
Heh okay I understand... Thank you for your answer.
Should I try and rewrite it so it will work better? Maybe other module
can perform this test?
|