473,387 Members | 1,540 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,387 software developers and data experts.

Help me choose a C++ compiler to work with Python

Just found Python and I love it. What an elegant language!
I would like to use it for various applications, but the
mathematical calculations are way too slow (a million sines 8 seconds
in Python vs. 2 seconds in Excel VBA), so was thinking of learning
enough C++ to do the number crunching in C++ and integrating the C++
routines with Python. My question:
My question:
Which compiler works best with Python?
I use Windows XP and 98. Have very little experience with C++. Am
doing statistical and other simulations that require billions of
calculations (taking 1 to 2 hours in Excel VBA). GCC is free, MS
C++.Net is affordable at <$100 but supposedly has problems until the
next version (and I could only use it on my XP machine), older
versions of MS C++ are no longer for sale. What's the most robust
solution? I would also like to make .dll files that I can plug into
MS Excel.
Sorry for the vagueness of this question, but I'm sure many of you
have experience with this and any information, opinions, and even
prejudices about the various compilers are welcome.
Thanks.
Jul 18 '05 #1
12 3085
rhmd wrote:

I use Windows XP and 98. Have very little experience with C++. Am
doing statistical and other simulations that require billions of
calculations


Have you considered and investigated Numeric Python or similar
products? Perhaps your assumption that you have to revert to
hand-crafted C code is premature.

-Peter
Jul 18 '05 #2

"rhmd" <rh*******@juno.com> wrote in message
news:61**************************@posting.google.c om...
Just found Python and I love it. What an elegant language!
Yeah, me too. :)
I would like to use it for various applications, but the
mathematical calculations are way too slow (a million sines 8 seconds
in Python vs. 2 seconds in Excel VBA), so was thinking of learning
enough C++ to do the number crunching in C++ and integrating the C++
routines with Python.
This one really has me squirming in my seat. C++ isn't a very good language
for learning just a little bit of. Compared to Python I would say the
learning curve is much steeper. It offers a lot of control over how the
object code is generated but that also makes it dangerous for casual users.
If you do it wrong a lot of bad things can happen, including poor
performance -- although poor performance would perhaps be the best of those
bad things!

I suggest you look at various Python libraries to do whatever numerical
processing you might need to do. They are mostly written in C anyway so
their performance is excellent. For instance, I use SciPy for Fourier
analysis and PIL for image processing, getting good performance on these
numerically intensive tasks without ever leaving the ease and comfort of
good old Python.

My question: My question:
Which compiler works best with Python?
I wouldn't choose your C++ compiler for Python compatibility. How good is
the debugger? How is the standards conformance? C++ compilers vary widely in
these and other important criteria.
I use Windows XP and 98. Have very little experience with C++. Am
doing statistical and other simulations that require billions of
calculations (taking 1 to 2 hours in Excel VBA).
Take a look at the UVS library under my sig for some C++ code which I have
found useful for statistical simulations.

GCC is free, MS C++.Net is affordable at <$100 but supposedly has problems until the
next version (and I could only use it on my XP machine), older
versions of MS C++ are no longer for sale. What's the most robust
solution?
The .NET compiler has a very good debugger and much better standard
compliance than the old 6.0 compiler, but I haven't used lot of different
recent vintage C++ compilers.

I would also like to make .dll files that I can plug into MS Excel.
I generally use COM objects written in Python to connect to Excel. I am very
pleased with that technique.

http://starship.python.net/crew/mhammond/
Sorry for the vagueness of this question, but I'm sure many of you
have experience with this and any information, opinions, and even
prejudices about the various compilers are welcome.
Thanks.


--
Cy
http://home.rochester.rr.com/cyhome/
Jul 18 '05 #3
"Cy Edmunds" <ce******@spamless.rochester.rr.com> writes:
"rhmd" <rh*******@juno.com> wrote in message
news:61**************************@posting.google.c om... [...] This one really has me squirming in my seat. C++ isn't a very good language
for learning just a little bit of. Compared to Python I would say the
Agreed! But Koenig & Moo's book (Accelerated C++) is the best I've
seen for doing that.

[...] I wouldn't choose your C++ compiler for Python compatibility. How good is
I don't think that's unreasonable, as long as you're *aware* of all
the other issues. Ease of use with standard Python might come out as
most important. And on Windows, Python work with MSVC is much less of
a pain for most things than gcc (aka mingw).

[...] The .NET compiler has a very good debugger and much better standard
compliance than the old 6.0 compiler, but I haven't used lot of different
recent vintage C++ compilers.


What *is* the current position with MSVC 7 and Python? Anyone? I
still haven't heard a clear story.
John
Jul 18 '05 #4
rh*******@juno.com (rhmd) writes:
[...]
I would like to use it for various applications, but the
mathematical calculations are way too slow (a million sines 8 seconds
in Python vs. 2 seconds in Excel VBA), so was thinking of learning
enough C++ to do the number crunching in C++ and integrating the C++
routines with Python. My question:

[...]

Do remember that frequently only small parts of your code (even the
number crunching part) are responsible for most of the running time.
Writing everything in Python then porting the 'hot spots' is often the
best strategy. Use the profiler.

Also (apart from Numeric / numarray), remember (or discover) Pyrex and
psyco. Probably Pyrex is more useful to you than psyco. Don't apply
either to your whole program. Just pick the bottlenecks.

Quite a few people here have touted O'Caml as a replacement for C++
for this kind of thing. C is worth considering, too, especially if
you find the parts you need to move down to a lower-level language are
small.

If you insist on using C++, make sure to look at Boost.Python
(including pyste).
John
Jul 18 '05 #5
Peter Hansen wrote:
rhmd wrote:
I use Windows XP and 98. Have very little experience with C++. Am
doing statistical and other simulations that require billions of
calculations


Have you considered and investigated Numeric Python or similar
products? Perhaps your assumption that you have to revert to
hand-crafted C code is premature.

-Peter


Look at the enthought Python installation (one is available for each
of 2.2 and 2.3) -- they not only install a slew of the packages you
might need for calculation heavy Python use, but (to support weave,
I believe), they also include a mingw32 compiler (minimal gnu win32)
which you can use for C++. If you get to the point where you are
optimization-bound on your compiler (which you should determine by
measuring, not intuiting), you could do worse than the Intel compiler.

-Scott David Daniels
Sc***********@Acm.Org

Jul 18 '05 #6
rh*******@juno.com (rhmd) wrote in message news:<61**************************@posting.google. com>...
Just found Python and I love it. What an elegant language!
I would like to use it for various applications, but the
mathematical calculations are way too slow (a million sines 8 seconds
in Python vs. 2 seconds in Excel VBA), so was thinking of learning
enough C++ to do the number crunching in C++ and integrating the C++
routines with Python. My question:
My question:
Which compiler works best with Python?
I use Windows XP and 98. Have very little experience with C++. Am
doing statistical and other simulations that require billions of
calculations (taking 1 to 2 hours in Excel VBA). GCC is free, MS
C++.Net is affordable
The standard C/C++ compiler (no optimization) is included in .Net
framework SDK, which is available for free in M$'s web-site.
at <$100 but supposedly has problems until the
next version (and I could only use it on my XP machine), older
versions of MS C++ are no longer for sale. What's the most robust
solution? I would also like to make .dll files that I can plug into
MS Excel.
Sorry for the vagueness of this question, but I'm sure many of you
have experience with this and any information, opinions, and even
prejudices about the various compilers are welcome.


I guess gcc is the only choice.. If you don't mind that it takes
forever to compile C++ source code, until version 3.4 is released (it
will supports pre-compiled header).
Jul 18 '05 #7
d2003xx wrote:
I use Windows XP and 98. Have very little experience with C++. Am
doing statistical and other simulations that require billions of
calculations (taking 1 to 2 hours in Excel VBA). GCC is free, MS
C++.Net is affordable


It is equally trivial to connect Python to Delphi using ctypes.
Delphi can easily make a DLL that looks to the outside world like
C. I have found Delphi to be maybe a little bit slower than MS C,
but a little faster than gcc. They are all pretty close on speed,
so you can't really pick a winner a priori. If you are doing VBA
now, can't you buy the entry-level version of VB for around 100
bucks and create C-callable DLL's?

Al
Jul 18 '05 #8
Thanks to all who have responded. Your information was very helpful,
I'm very impressed with the quality and thoughtfulness of the
responses. Below find brief excerpts of some of the responses (which
I hope will be useful for others who search for info on this topic),
followed by more detail on my question.

BEGIN EXCERPTS
Have you considered and investigated Numeric Python or similar
products?
Look at the enthought Python installation (one is available for each
of 2.2 and 2.3) -- they not only install a slew of the packages you
might need for calculation heavy Python use, but (to support weave,
I believe), they also include a mingw32 compiler (minimal gnu win32)
which you can use for C++. If you get to the point where you are
optimization-bound on your compiler (which you should determine by
measuring, not intuiting), you could do worse than the Intel compiler.
I suggest you look at various Python libraries to do whatever
numerical
processing you might need to do. They are mostly written in C anyway
so
their performance is excellent. For instance, I use SciPy for Fourier
analysis and PIL for image processing, getting good performance on
these
numerically intensive tasks without ever leaving the ease and comfort
of
good old Python....The .NET compiler has a very good debugger and much
better standard compliance than the old 6.0 compiler, but I haven't
used lot of different recent vintage C++ compilers...I generally use
COM objects written in Python to connect to Excel. I am very pleased
with that technique.

Koenig & Moo's book (Accelerated C++) is the best I've
seen for [learning C++ for a few applications]..Python work with MSVC
is much less of a pain for most things than gcc (aka mingw).
Writing everything in Python then porting the 'hot spots' is often
the
best strategy. Use the profiler.
Also (apart from Numeric / numarray), remember (or discover) Pyrex
and
psyco. Probably Pyrex is more useful to you than psyco. Don't apply
either to your whole program. Just pick the bottlenecks. If you
insist on using C++, make sure to look at Boost.Python(including
pyste).
gcc ... If you don't mind that it takes
forever to compile C++ source code, until version 3.4 is released (it
will support pre-compiled header).
It is equally trivial to connect Python to Delphi using ctypes.
Delphi can easily make a DLL that looks to the outside world like
C. I have found Delphi to be maybe a little bit slower than MS C,
but a little faster than gcc. They are all pretty close on speed,
so you can't really pick a winner a priori. If you are doing VBA
now, can't you buy the entry-level version of VB for around 100
bucks and create C-callable DLL's?
END EXCERPTS

MORE DETAIL ON MY QUESTION
VB.NET was another option I considered, have heard it produces
binary that runs "almost" as fast as that produced by C++, but am not
sure if that is true. VB would be very convenient for me, but can it
produce DLLs that Python can use? The reason I was considering using
Python/C++ combination is that I use Python already (as scripting
language for the Blender animation program) and thought I could also
use it with Excel to overcome certain Excel limitations, such as
Excel's ridiculous limitations on chart markers (i.e., could make
better charts with Python-- this would not be a time bottleneck so
Python's slowness is not an issue there), etc. I also thought that,
despite Python's reputation for being a bit slow, it would at least be
faster than Excel VBA interpreter, but this may not be the case. At
any rate, there are some calculations where I need a LOT of speed,
e.g. generating billions (with a B) of random numbers with the
Mersenne Twister algorithm (which is available in C++), for
statistical problems (mulitple undefined boundary conditions which can
only be extracted with a Monte Carlo method). For this, even doubling
or quadrupling Python binary's speed would not be enough.
Jul 18 '05 #9
rhmd wrote:


MORE DETAIL ON MY QUESTION At
any rate, there are some calculations where I need a LOT of speed,
e.g. generating billions (with a B) of random numbers with the
Mersenne Twister algorithm


Off the top of my head I don't know which rng RandomArray (part of Numeric)
uses, but its speed is not that bad:

In [20]: def rloop(n,m):
....: random = RA.random
....: size=10**m
....: for i in xrange(10**n):
....: _=random(size)
....:

In [21]: timing (1,rloop,1,5) # times are in cpu seconds
Out[21]: 0.12000000000000455

In [22]: timing (1,rloop,2,5)
Out[22]: 1.1999999999999957

In [23]: timing (1,rloop,3,5)
Out[23]: 12.469999999999999
The scaling is pretty linear, so for a billion terms you'd need about 2
minutes.

hth.

Cheers,

f
Jul 18 '05 #10
Fernando Perez wrote:
...
e.g. generating billions (with a B) of random numbers with the
Mersenne Twister algorithm
Off the top of my head I don't know which rng RandomArray (part of
Numeric) uses, but its speed is not that bad:

... The scaling is pretty linear, so for a billion terms you'd need about 2
minutes.
Similar orders of magnitude for the built-in random number generator,
which IS a Mersenne Twister in Python 2.3 -- at least on my old trusty
Athlon box (no doubt today's CPU's would easily take 3 or 4 times less):

[alex@lancelot python2.3]$ python timeit.py \ -s "from random import random" \
-s "times=[None]*1000"
"for x in times: random()"

1000 loops, best of 3: 380 usec per loop

380 microseconds for 1,000 calls to random.random(), and here, too,
very linear scaling, suggests about 380 seconds for a billion calls,
i.e., about 6 or 7 minutes, on this old machine.
Alex

Jul 18 '05 #11
Alex Martelli <al***@aleax.it> wrote in message news:<yF**********************@news1.tin.it>...

Similar orders of magnitude for the built-in random number generator,
which IS a Mersenne Twister in Python 2.3 -- at least on my old trusty
Athlon box (no doubt today's CPU's would easily take 3 or 4 times less):

[alex@lancelot python2.3]$ python timeit.py \
-s "from random import random" \
-s "times=[None]*1000"
"for x in times: random()"

1000 loops, best of 3: 380 usec per loop

380 microseconds for 1,000 calls to random.random(), and here, too,
very linear scaling, suggests about 380 seconds for a billion calls,
i.e., about 6 or 7 minutes, on this old machine.


Wow! I didn't realize that 2.3 had upgraded to Mersenne Twister
(which has a period of more than 10**10000, vs. WichmannHill which has
a period of less than 10**10 and the Excel 2000 PNRG which (to my
shock and chagrin) had a period of about 10**7). This is awesome.
Jul 18 '05 #12
There was an error in my previous message Wichmann Hill has a period
of less than 10**14 (not 10**10)

rh*******@juno.com (rhmd) wrote in message news:<61**************************@posting.google. com>...
Alex Martelli <al***@aleax.it> wrote in message news:<yF**********************@news1.tin.it>...

Similar orders of magnitude for the built-in random number generator,
which IS a Mersenne Twister in Python 2.3 -- at least on my old trusty
Athlon box (no doubt today's CPU's would easily take 3 or 4 times less):

[alex@lancelot python2.3]$ python timeit.py \
-s "from random import random" \
-s "times=[None]*1000"
"for x in times: random()"

1000 loops, best of 3: 380 usec per loop

380 microseconds for 1,000 calls to random.random(), and here, too,
very linear scaling, suggests about 380 seconds for a billion calls,
i.e., about 6 or 7 minutes, on this old machine.


Wow! I didn't realize that 2.3 had upgraded to Mersenne Twister
(which has a period of more than 10**10000, vs. WichmannHill which has
a period of less than 10**10 and the Excel 2000 PNRG which (to my
shock and chagrin) had a period of about 10**7). This is awesome.

Jul 18 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

188
by: Ilias Lazaridis | last post by:
I'm a newcomer to python: - E01: The Java Failure - May Python Helps? http://groups-beta.google.com/group/comp.lang.python/msg/75f0c5c35374f553 - I've download (as suggested) the python...
9
by: vj | last post by:
When I run the setup.py script , it throws an error Traceback (most recent call last): File "C:\vijay\db2\utils\PyDB2-1.1.0-2.tar\PyDB2-1.1.0\setup.py", line 57, in -toplevel- libraries=, File...
22
by: Rafia Tapia | last post by:
Hi all This is what I have in mind and I will appreciate any suggestions. I am trying to create a xml help system for my application. The schema of the xml file will be <helpsystem> <help...
2
by: Michael Hudson | last post by:
The PyPy development team has been busy working and we've now packaged our latest improvements, completed work and new experiments as version 0.9.0, our fourth public release. The highlights of...
31
by: Mark Dufour | last post by:
Hi all, I have recently released version 0.0.20 and 0.0.21 of Shed Skin, an optimizing Python-to-C++ compiler. Shed Skin allows for translation of pure (unmodified), implicitly statically typed...
12
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed...
17
by: chewie54 | last post by:
Hello, As an electronics engineer I use some very expensive EDA CAD tool programs that are scriptable using Tcl. I was wondering why these companies have choose to use Tcl instead of Python. ...
7
by: Protected | last post by:
Hello. I'm a complete newbie trying to learn Python. I decided to try some Tkinter examples, including the one from the library reference, but they don't seem to do anything! Shouldn't there be,...
15
by: colemanj4 | last post by:
Here is what I have so far, it loops while the PW is incorrect, or until cancel is selected. I want it to lock the tables for adds, deletes, and edits when cancel is selected, and if the PW is...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...

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.