473,287 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

gmpy

5
python 2.5.2
ubuntu 8.04 LTS

(1) I find that python/gmpy is about 3 times slower than c++/gmp.
Is this the general experience, or am I doing something wrong?

(2) I am unable to understand the following error in conversion from float() to gmpy.mpf() or how to avoid it:

Expand|Select|Wrap|Line Numbers
  1. import gmpy
  2. gmpy.set_minprec(100)
  3. t= gmpy.mpf(7.99)
  4. print t
  5. print t/3
  6.  
prints:
7.990000000000000213162820728030055761337
2.663333333333333404387606909343351920446

I am new to both linux and python and would appreciate any expert help.

zakad
Sep 29 '08 #1
3 3722
casevh
2
Hi,

Can you provide an example for performance question?

Python will have more overhead for each function call, so it will be slower when making multiple calls. The amount of slowdown should decrease as the size of the numbers increases.

Regarding your conversion question, you are converting the floating point approximation to 7.99 which is only accurate to about 18 decimal digits. If you convert the string "7.99" to an mpf, you'll get the value that I think you are expecting.

casevh
Oct 3 '08 #2
zakad
5
I found the following draft in my computer, but apparently, for some reason, it has never been posted. So, with apologies to casevh, here it is:

Thank you, casevh. Your reply certainly answered my question as to the conversion from float (or double) to mpf . I failed to find the answer through googling.
With regard to my first question re/ the speed of Python relative to C++, the program that I tested is based on binary splitting which, as you know, entails recursive calls to a function from within the function itself. All operations are on integers (the largest being 9092390 decimal digits long). Then, there is a single final floating point division. The results were : python/gmpy 81.638, C++/GMP 28.800 sec.
Your comment that Python has more overhead for each function call may partly explain the relative slowness of Python. I have since come across articles that suggest that Python is significantly slower in performing simple arithmetic operations. See, for example:
http://furryland.org/~mikec/bench/
Lastly, there is a clear difference between Python and C++. Whereas in C++ the type of each operand is strictly defined at the time it is declared, Python mostly leaves the definition to the "context" during run-time. This may cause slowness and is a potential source of confusion to programmer and program alike. It is a pity because I have come to enjoy Python as a language of simple elegance as well as power and accuracy.
Aug 17 '09 #3
casevh
2
Hello, if you are still interested in trying to resolve the performance differences, I have a question/suggestion.

Is it always approximately 3x slower, or does it get worse when the numbers are very large? The current beta version is more efficient with memory handling and that may make a difference.

If that doesn't make a difference, can you post the code?

casevh
Sep 11 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Jean-Pierre Andreaux | last post by:
Gmpy module was a wrapper of the GNU MP library. It seems that no evolution is done on this module since 2001. Indeed, Gmpy is not supported in Python 2.2 nor 2.3. My question is the following:...
2
by: Mensanator | last post by:
In the program that follows, I get the following warning message: collatz_.py:37: RuntimeWarning: tp_compare didn't return -1, 0 or 1 while b>1: In this case, b is a gmpy.mpz number. The...
11
by: Alex Martelli | last post by:
Thanks to David Bolen, who did the build, I have been able to make available a win32 packaging for gmpy 1.0 on python 2.4 alpha 2 (should work on any later Python 2.4 as well, but I have no way to...
3
by: mensanator | last post by:
Since the following discussion took place (unresolved), ...
22
by: Alex Martelli | last post by:
I have fixed almost all of the outstanding bugreports and feature request for gmpy: divm doesn't leak memory any more, truediv and floordiv are implemented for all types, etc -- in the current CVS...
0
by: Alex Martelli | last post by:
I've added to gmpy.sf.net two binary packages of gmpy for Mac OS X 10.4, one for the Python 2.3.5 that comes with the system and one for Bob Ippolito's build of 2.4.1. They still need GMP to be...
3
by: Alex Martelli | last post by:
As things stand now (gmpy 1.01), an instance d of decimal.Decimal cannot transparently become an instance of any of gmpy.{mpz, mpq, mpf}, nor vice versa (the conversions are all possible, but a bit...
3
by: mensanator | last post by:
## Holy Mother of Pearl! ## ## >>> for i in range(10): ## for j in range(10): ## print '%4d' % (gmpy.mpz(i)*gmpy.mpz(j)), ## print ## ## ## ...
7
by: | last post by:
Hi, I just stumbled upon the following issue (I am running Debian): $ python Python 2.5.2 (r252:60911, Sep 29 2008, 21:15:13) on linux2 Type "help", "copyright", "credits" or "license" for...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.