in reply to Re^10: Module for 128-bit integer math?
in thread Module for 128-bit integer math?
BrowserUk (or anyone else, of course), if you want a ppm package
Thanks syphilis. That works perfectly.
And especially thanks to salva.
I still intend to pursue an MSVC/SSE* solution to this, but this gives me a reference point.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^12: Module for 128-bit integer math?
by syphilis (Archbishop) on Feb 12, 2011 at 04:10 UTC | |
I'll second that !! There are of course, more things to consider than just *performance* when it comes to choosing which Math module to use - but I was curious to see how Math::Int128 compared for speed with Math::GMPz (which uses the gmp C library). I found that, if using overloaded operators with Math::GMPz, then Math::GMPz was roughly twice as slow as Math::Int128 - but if using the arithmetic functions that Math::GMPz also provides, then Math::GMPz was roughly twice as fast as Math::Int128. Without yet having taken the time to look closely at Math::Int128, I believe there would be a way of having it out-perform Math::GMPz. (And I'm about to embark upon a little excercise to satisfy myself that this is so.) For any Windows users who want to check the comparisons for themselves, there are ppm packages for 64-bit perl (5.10 and 5.12) available: The benchmarks I ran are as follows: The output I got was: Update: I've since written an Inline::C script where the __int128 multiplications beat Math::GMPz ... but not by much: The code I used is still a bit rough, but I don't see much scope for improvement at the moment. Cheers, Rob | [reply] [d/l] [select] |
by BrowserUk (Patriarch) on Feb 12, 2011 at 10:08 UTC | |
That's interesting, but there are reasons other than performance for wanting fix-width integer semantics. Try coding this with GMP (or any arbitrary precision math):
Note: I would have supplied a GMPz version, Update: Here's my attempt at a GMP version of the above. Note that it doesn't just produce the wrong results, but it does so silently:
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.
| [reply] [d/l] [select] |
by syphilis (Archbishop) on Feb 12, 2011 at 14:30 UTC | |
Definitely correct ... though I must confess that the reasons you've implicitly put forward in your demos were not exactly what I was thinking of when I acknowledged this (or tried to) in my earlier post. For a Math::GMPz rendition of your demo I would put forward the following: I hope it doesn't miss the point ... I think the only changes are that: 1) It changes the way that $ALLONES is created; 2) It removes the need for sub bcount() Update: And, there's also now a qw(:mpz) in the third line. Cheers, Rob | [reply] [d/l] [select] |
by BrowserUk (Patriarch) on Feb 12, 2011 at 14:41 UTC | |
by syphilis (Archbishop) on Feb 13, 2011 at 00:14 UTC | |
| |
by salva (Canon) on Feb 14, 2011 at 12:01 UTC | |
but I don't see much scope for improvement at the moment Well, there is... The G2 version is faster than G1 and I because it is not allocating and deallocating the result object every time but reusing $mpz_ret. After adding to Math::Int128 a new set of operators that use a preallocated argument for output, Math::Int128 becomes faster than Math::GMPz, around 60% faster. The modified benchmark script: Read more... (3 kB)
And the results I get on my 64bits-linux-but-with-a-not-very-optimized-for-64bits-old-processor: The new version of the module can be obtained from GitHub. | [reply] [d/l] [select] |
by syphilis (Archbishop) on Feb 15, 2011 at 11:14 UTC | |
Using the latest version of Math::Int128, and your modified script, I find an improvement (on Windows Vista) of around 40%. Given that we're using different operating systems and probably different processors, I think we can agree that "I find the same as you". Cheers, Rob I should add that even 40% is better than I could get with my approach to Math::Int128 modifications. I might learn something if I ever find the time and energy to discover why that was so. (Best I could get was to have the int128 arithemtic about 5-10% faster than Math::GMPz.) | [reply] |
by salva (Canon) on Feb 15, 2011 at 11:46 UTC | |
by syphilis (Archbishop) on Feb 15, 2011 at 13:40 UTC | |
by syphilis (Archbishop) on Feb 14, 2011 at 20:53 UTC | |
That's more like the figures I anticipated (at a guess). My "I don't see much scope for improvement" comment was in relation to my own enhancements to Math::Int128 which removed the allocating/deallocating you mentioned - and which made the int128 multiplication a little faster than using Math::GMPz's functions (and, of course, significantly faster than using Math::GMPz's overloaded operators). When I get back to my Vista64 box, I'll grab the latest github version and see for myself ... and, of course, post again with my results for that machine. Cheers, Rob | [reply] |