473,383 Members | 1,843 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,383 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 3728
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.