It does depend rather on exactly what you are doing.
There is quite a bit more overhead in creating a gmp.Int vs a big.Int,
however GMP runs much quicker when the numbers get bigger because it has
a range of extremely efficient algorithms.
To give a concrete example on a pi calculating program, math/big is
slightly ahead up to a length of 4,000 digits but by 1,000,000 digits
gmp is 47x times quicker.
The only time the gmp based library is a lot slower is if you are
creating and destroying lots of numbers quickly and that is usually
something you can easily optimize (by re-using numbers) which helps the
performance of both the math/big and the gmp solutions.
On 09/10/13 21:20, Michael Jones wrote:
> How fast is "very much"? More than 2-3x for your program's overall runtime?
>
>
> On Wed, Oct 9, 2013 at 9:38 AM, Nick Craig-Wood <
ni...@craig-wood.com
> <mailto:
ni...@craig-wood.com>> wrote:
>
> I decided to make an industrial strength drop in replacement for
> math/big using GMP. You can just change the import and enjoy the super
> speed of GMP in your go programs!
>
>
https://github.com/ncw/gmp
>
> GMP is very much faster than Go's math/big however it is an external C
> library with all the problems that entails (cgo, dependencies etc)
>
> This library was made by taking the cgo example of wrapping GMP from the
> Go source and doing the following to it
>
> * Copying the implementation from misc/cgo/gmp/gmp.go
> * Copying the documentation from src/pkg/math/big/int.go
> * Additional implementation of missing methods
> * Bug fixes for existing implementations
> * Making it passes the test suite from src/pkg/math/big/int_test.go
> * Adding memory management
> * Fix problems on 32 bit platforms when using int64 values which don't
> fit into a C.long
>
> See here for package docs
>
>
http://go.pkgdoc.org/github.com/ncw/gmp
>
> --
> Nick Craig-Wood <
ni...@craig-wood.com <mailto:
ni...@craig-wood.com>>
> <mailto:
golang-nuts%2Bunsu...@googlegroups.com>.
> <mailto:
m...@google.com> |
+1 650-335-5765