FAQ
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 <nick@craig-wood.com> -- http://www.craig-wood.com/nick

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Michael Jones at Oct 9, 2013 at 8:21 pm
    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 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 <nick@craig-wood.com> -- http://www.craig-wood.com/nick

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    Michael T. Jones | Chief Technology Advocate | mtj@google.com | +1
    650-335-5765

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Nick Craig-Wood at Oct 9, 2013 at 9:47 pm
    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 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 <nick@craig-wood.com -- http://www.craig-wood.com/nick

    --
    You received this message because you are subscribed to the Google
    Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it,
    send an email to golang-nuts+unsubscribe@googlegroups.com
    For more options, visit https://groups.google.com/groups/opt_out.




    --
    Michael T. Jones | Chief Technology Advocate | mtj@google.com
    +1 650-335-5765

    --
    Nick Craig-Wood <nick@craig-wood.com> -- http://www.craig-wood.com/nick

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Michael Jones at Oct 9, 2013 at 11:23 pm

    On Wed, Oct 9, 2013 at 2:47 PM, Nick Craig-Wood wrote:

    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.
    Thanks! We need more special multiply cases. There has already been work
    toward this and it makes sense to review after the release.


    --
    Michael T. Jones | Chief Technology Advocate | mtj@google.com | +1
    650-335-5765

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Nick Craig-Wood at Oct 10, 2013 at 11:03 am

    On 10/10/13 00:22, Michael Jones wrote:

    On Wed, Oct 9, 2013 at 2:47 PM, Nick Craig-Wood wrote:

    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.

    Thanks! We need more special multiply cases. There has already been work
    toward this and it makes sense to review after the release.
    Don't get me wrong - I think math/big is an amazing piece of work.

    However the sheer number of man years of effort that have gone into GMP
    make it very hard to beat in my experience.

    BTW I have two patches I'll propose for math/big at some point, one
    speeding up the basic arithmetic for ARM and another with some more test
    cases.

    --
    Nick Craig-Wood <nick@craig-wood.com> -- http://www.craig-wood.com/nick

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Rémy Oudompheng at Oct 10, 2013 at 11:31 am
    You might be interested in github.com/remyoudompheng/bigfft
    for very large integer arithmetic (multiplication).

    It is written in Go and shares the existing assembly routines of math/big.

    Rémy.

    2013/10/10, Nick Craig-Wood <nick@craig-wood.com>:
    On 10/10/13 00:22, Michael Jones wrote:

    On Wed, Oct 9, 2013 at 2:47 PM, Nick Craig-Wood <nick@craig-wood.com
    wrote:

    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.

    Thanks! We need more special multiply cases. There has already been work
    toward this and it makes sense to review after the release.
    Don't get me wrong - I think math/big is an amazing piece of work.

    However the sheer number of man years of effort that have gone into GMP
    make it very hard to beat in my experience.

    BTW I have two patches I'll propose for math/big at some point, one
    speeding up the basic arithmetic for ARM and another with some more test
    cases.

    --
    Nick Craig-Wood <nick@craig-wood.com> -- http://www.craig-wood.com/nick

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jan Mercl at Oct 10, 2013 at 11:37 am

    On Thu, Oct 10, 2013 at 1:31 PM, Rémy Oudompheng wrote:
    You might be interested in github.com/remyoudompheng/bigfft
    for very large integer arithmetic (multiplication).

    It is written in Go and shares the existing assembly routines of math/big.
    Your package is used by [0] and I can confirm the speedups are as
    documented. Big (integer) thanks! ;-)

       [0]: https://github.com/cznic/mathutil/blob/master/mersenne/mersenne.go#L252

    -j

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 9, '13 at 4:38p
activeOct 10, '13 at 11:37a
posts7
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase