Skip to content

Instantly share code, notes, and snippets.

@prakashk
Created September 12, 2013 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prakashk/6540327 to your computer and use it in GitHub Desktop.
Save prakashk/6540327 to your computer and use it in GitHub Desktop.
Math::BigFloat vs Math::Pari
#!/usr/bin/env perl
use Benchmark qw/:all :hireswallclock/;
use Math::BigFloat;
use Math::Pari;
my $count = shift || 10_000;
my $pressure_bf = Math::BigFloat->new(1011.4598);
my $pressure_pari = Math::Pari::PARI(1011.4598);
# my $pressure = 1011.4598;
cmpthese(
$count,
{
bigfloat => sub { (1 - (($pressure_bf / 1013) ** (0.190263))) * 44330.8 },
parifloat => sub { (1 - (($pressure_pari / 1013) ** (0.190263))) * 44330.8 },
# nativefloat => sub { (1 - (($pressure / 1013) ** (0.190263))) * 44330.8 },
}
);
@prakashk
Copy link
Author

Output:

            (warning: too few iterations for a reliable count)
            Rate bigfloat     pari
bigfloat  47.4/s       --    -100%
pari     90909/s  191855%       --

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment