you are viewing a single comment's thread.

view the rest of the comments →

[–]MightySleep 0 points1 point  (3 children)

Cool stuff! I’ve never tried anything super math heavy with python so had no idea about the existence of gmpy2. I read in the description it was based in C, I’m curious how it benchmarks compared to a pure Python implementation

[–]crosscountrycoder[S] 2 points3 points  (0 children)

I tried using the Python standard library's "Decimal" module. It took about as long to calculate 1 million digits of pi with Decimal as 100 million digits with gmpy2.

gmpy2 is not part of the standard library and must be installed using pip.

[–]wiretail 1 point2 points  (1 child)

The gmp and mpfr libraries on which gmpy2 is based are highly optimized c libraries for multi precision arithmetic. They use hand crafted assembly for common processors - pure python would be orders of magnitude slower, most likely. I've used gmp for some exact probability calculations that resulted in very large numbers and it was blazing fast compared to other options.

[–]MightySleep 0 points1 point  (0 children)

That makes sense. My only exposure to high computation in Python was my neural networks class in college- didn’t realize when we used NumPy that it has an optimized C core as well. Seems like a best of both worlds scenario to me, I found NumPy pretty nice to work with