I stumbled across it while trying to add some speedups to Math-GMP

Nice post ++, btw.
I've always assumed that if you want to get the maximum performance out of Math::GMP, then you'll avoid the overloading altogether and explicitly make the method calls.
I think this is generally true and the following script seems to support that view, though it only compares the 2 ways of performing a right shift.
use warnings; use Benchmark; use Math::GMP; no warnings 'once'; $str1 = '123456789' x 1000; $gmp1 = Math::GMP->new($str1); timethese(100000, { 'Math::GMP 1' => '$ret1 = $gmp1 >> 1000;', 'Math::GMP 2' => '$ret2 = $gmp1->div_2exp_gmp(1000)', }); print "gmp calculation ok\n" if $ret1 == $ret2; __END__ Outputs: Benchmark: timing 100000 iterations of Math::GMP 1, Math::GMP 2... Math::GMP 1: 0 wallclock secs ( 0.19 usr + 0.00 sys = 0.19 CPU) @ 5 +34759.36/s (n=100000) (warning: too few iterations for a reliable count) Math::GMP 2: 0 wallclock secs ( 0.12 usr + 0.00 sys = 0.12 CPU) @ 8 +00000.00/s (n=100000) (warning: too few iterations for a reliable count) gmp calculation ok
I might as well showcase my own Math::GMPz module while I'm at it, though I see it's main benefit as being that it enwraps much more of the gmp library than is covered by Math::GMP.
use warnings; use Benchmark; use Math::GMP; use Math::GMPz qw(:mpz); no warnings 'once'; $str1 = '123456789' x 1000; $gmp1 = Math::GMP->new ($str1); $gmpz1 = Math::GMPz->new($str1); $ret4 = Math::GMPz->new(); timethese(100000, { 'Math::GMP 1' => '$ret1 = $gmp1 >> 1000;', 'Math::GMP 2' => '$ret2 = $gmp1->div_2exp_gmp(1000);', 'Math::GMPz 1' => '$ret3 = $gmpz1 >> 1000;', 'Math::GMPz 2' => 'Rmpz_div_2exp($ret4, $gmpz1, 1000);', }); print "gmp calcualtion ok\n" if $ret1 == $ret2; print "gmpz calculation ok\n" if $ret3 == $ret4; print "both gmp and gmpz agree\n" if "$ret1" eq "$ret3"; __END__ Outputs: Benchmark: timing 100000 iterations of Math::GMP 1, Math::GMP 2, Math: +:GMPz 1, Math::GMPz 2... Math::GMP 1: 0 wallclock secs ( 0.19 usr + 0.00 sys = 0.19 CPU) @ 5 +34759.36/s (n=100000) (warning: too few iterations for a reliable count) Math::GMP 2: 0 wallclock secs ( 0.12 usr + 0.00 sys = 0.12 CPU) @ 8 +00000.00/s (n=100000) (warning: too few iterations for a reliable count) Math::GMPz 1: 0 wallclock secs ( 0.09 usr + 0.00 sys = 0.09 CPU) @ +1063829.79/s (n=100000) (warning: too few iterations for a reliable count) Math::GMPz 2: 0 wallclock secs ( 0.03 usr + 0.00 sys = 0.03 CPU) @ +3225806.45/s (n=100000) (warning: too few iterations for a reliable count) gmp calcualtion ok gmpz calculation ok both gmp and gmpz agree
Both Math::GMP and Math::GMPz were built against the very same gmp-6.2.1 library.

Cheers,
Rob

In reply to Re: Calling an overload::Method by syphilis
in thread Calling an overload::Method by hv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.