The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.
#!/usr/bin/perl -w

use strict;
use Math::Pari qw/isprime/;
use Math::Primality qw/is_prime/;
use Benchmark qw/:all/;
my $count = shift || 10000;

my $magnitude = 10;
my @small_nums = map { "$_" } map { int(1+rand(9)) ** $magnitude) } (1..50);

print "Benchmarking Math::Primality version $Math::Primality::VERSION against Math::Pari version $Math::Pari::VERSION\n";
print "Psuedorandom numbers of magnitude 10 ^ $magnitude\n";

cmpthese($count,{
    'is_prime' => sub { is_prime($_) for @small_nums },
    'isprime' => sub { isprime($_) for @small_nums },
});