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: -
import gmpy
-
gmpy.set_minprec(100)
-
t= gmpy.mpf(7.99)
-
print t
-
print t/3
-
prints:
7.9900000000000 002131628207280 30055761337
2.6633333333333 334043876069093 43351920446
I am new to both linux and python and would appreciate any expert help.
zakad
3 3741
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
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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: what is the better replacement solution
for manipulating long numbers. I want to do long numbers
exponentiations. Thanks in advance for your answers.
JP
|
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 program operates as it should,
which I guess is why it's a warning. Is there some reason why I shouldn't
use gmpy numbers with relational operators? Is this warning something
that can safely be ignored?
|
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 check it at
all). I can't reach sourceforge at the moment, so I have meanwhile put
the exe file up at:
http://www.aleax.it/Python/gmpy-1.0.win32-py2.4.exe
Users of both gmpy and python 2.4 on windows are invited to dowload and
install this,...
|
by: mensanator |
last post by:
Since the following discussion took place (unresolved),
<http://groups.google.com/group/comp.lang.python/browse_frm/thread/c3bd08ef3e4c478a/2b54deb522c9b9d9?lnk=st&q=divm()+memory+leak+group:comp.lang.python+author:mensanator&rnum=1&hl=en#2b54deb522c9b9d9>
I've kept it in the back of my mind as I've been
learning to use the base gmp library in c. Now I believe
I know what the problem is.
First, divm() is not a gmp function. It is a...
|
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
version (one thing I must still look at is divm's behavior when its args
are not mutually prime). It currently compiles w/o warnings, and passes
all of its 1040+ tests, w/the current release of GMP (4.1.4), Python
(2.4.2), MacOSX (10.4.3), XCode...
| |
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 previously
installed (I'm told the one that comes with fink works; I installed my
own from sources, from the GMP's site at swox.com), and they're .tar.gz
packages requiring unpacking with tar xzf from the Terminal -- so, not
very Mackish -- but...
|
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 laborious, e.g.
by explicitly going through string-forms).
I'm thinking about possible ways to fix this, in whole or in part, but,
before I spend more time on this, I was wondering if there's anybody
else who'd be interested -- if so, maybe we...
|
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
##
##
## 0 0 0 0 0 0 0 0 0 0
## 0 1 2 3 1 5 6 7 2 9
|
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 more information.
1
Traceback (most recent call last):
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |