Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^5: bigint == horrible performance?

by syphilis (Chancellor)
on Nov 08, 2011 at 12:17 UTC ( #936766=note: print w/replies, xml ) Need Help??

in reply to Re^4: bigint == horrible performance?
in thread bigint == horrible performance?

Arbitrary precision math is, regardless of the language in which it is written, much, much slower than fixed precision

I didn't do any benchmarking but my hunch is that the real slowdown wrt the op's code (when used with bigint) came about as a result of the multiplication and division operators being replaced by function calls.

But then ... replacement of "operators" with "function calls" is really part and parcel of how arbitrary precision math works, so I'm not sure that stating my "hunch" actually contributes anything terribly useful ... even if it *is* correct.


Replies are listed 'Best First'.
Re^6: bigint == horrible performance?
by BrowserUk (Pope) on Nov 08, 2011 at 15:27 UTC

    The slowdown comes in (at least) three stages. Perhaps more depending upon which back-end is being used behind the bigint front of house.

    1. Overloading the operators adds one level of subroutine call to each math op.
    2. The call into the back-end library adds a second.
    3. A third level comes from getting access to the memory in which the numbers are actually stored.

      With native opcodes, the value is at a fixed offset and the actual operations are essentially a single assembler instruction (processor opcode).

      With the libraries, you have the XS to C wrapping layer, then the library call, then dereferenceing and casting to get access to the number hanging off the PV.

      And with arbitrary precision and larger-than-register fixed precision, you have the condition testing to see if the number has multiple elements and the loops needed to propagate carries etc.

    I was not laying any criticisms. If you need the precision, then the costs -- whatever they are -- simply have to be paid. But using bigint 'just in case', or as a 'cure' for perceived 'inaccuracies' in floating point is the wrong way to go.

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://936766]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2018-05-21 21:44 GMT
Find Nodes?
    Voting Booth?