Question about scientific calculations in Python

Martin Kaufmann martinkaufmann at yahoo.com
Tue Mar 12 17:24:07 EST 2002


On 12 Mar 2002 15:41:32 GMT, hat at se-46.wpa.wtb.tue.nl (Albert Hofkamp)
wrote:

>On Wed, 13 Mar 2002 01:22:18 +1300, Martin Kaufmann <martinkaufmann at yahoo.com> wrote:
>
>In general, there are at least 2 steps in a problem:
>- Figure out what to do (what should I do in what order to obtain correct
>  results, how should I organize my software).
>- Figure out how to do it fast enough.
>
>Python is extremely well suited for the first step. It is high level, so
>experimenting can be done fast, without digging for low-level coding errors
>(for example, the amount of code needed to implement a dictionary correctly is
>quite astonishing with ample opportunity to make hard-to-find errors).
>Being high-level also gives you the benefit that you can concentrate on finding
>a good algorithm. Use as much libraries of Python as possible, as they tend to
>be optimized for their task (and it saves you from having to code it).

But if I then want to change to C I have to write all the functions
for which I had a library in Python.

>If you program well, and not use too many dynamic features of Python, you can
>consider the code as a kind of prototype for an implementation in e.g. C.
>Also, selecting a good algorithm has in general more impact on execution
>speed than optimizing a bad algorithm.
>
>'Fast enough' in the second step heavily depends on your expectations and/or
>requirements. I always try it first, and if I think it should be calculated
>faster, then I think about speed.
>First of all, if you can break the computation in independant pieces, do so,
>and use more than 1 computer. If that is not enough, see whether you can use
>faster or different libraries. If that is not enough, then re-code the program
>in C/C++ (which should be not too difficult, since you already have explored
>the best way to implement the program using Python (i.e. you don't need to do
>step 1 again).

In our group we already have a similar program written in C which is
may times faster. I just started in Python because I wanted to know
how much slower it is and because I don't know C...

>As a rule of the thumb I use that I need to save at least as much time running
>the program, as I am spending on writing it.
>Thus if by re-implementing, I save 1 hour execution time, and I run it 10
>times, then I must be able to rewrite the code in 10 hours, otherwise I am
>wasting time.
>(if you want to learn a language, this rule doesn't always hold of course).

I will have to rerun it for a lot more than 10 times. And during a PhD
thesis the "wasting of time" is not always the biggest issue...

Regards,

Martin



More information about the Python-list mailing list