code optimization (calc PI)
mm
michael at mustun.ch
Wed Jan 3 10:50:27 EST 2007
Hmm... it's a question. It was not that easy to translate this #@*?%!
C-Program into readable code and then to Python. But it works.
There are only two while-loops (a while within an other while).
I konw, that for example while-loops in Perl are very slow. Maybe this
is also known in Pyhton. Then, I can translate the while-loops in to
for-loops, for example.
More general, maybe there is a speed optimazation docu out there.
(Anyway, this code for C-calc is complex. And I realy don't understand
it right now... 8-)
But anyway, there is not that much calculation, it has more something to
do with the too while-loops. Here is some code:
(In general, it has basically nothing to do with PI-calc.)
c=2800 ## a counter
while c*2:
## do some calc. did not change c here.
...
b=c ## number of elements
while (b-1):
## so some calc.
...
b=b-1 ## just for while-loop condition.
c = c-14; ## this is code vor the 1st while-loop, BUT bust run after
the 2nd-while-loop.
pi = pi + str("%04d" % int(e + d/a)) ## this should be fast?! I dont
know.
There are a output string, a list, and integers. No complex data
structures; and no complex calculations.
Diez B. Roggisch wrote:
> mm wrote:
>
>
>>(Yes, I konw whats an object is...)
>>BTW. I did a translation of a pi callculation programm in C to Python.
>>(Do it by your own... ;-)
>
>
> Is that a question on how to optimize code you won't show us? If yes, I'm
> sorry to tell you that crystal balls are short these days. Too much
> new-year-outlooks.
>
> Diez
More information about the Python-list
mailing list