Python IS slow ! [was] Re: Python too slow for real world
Markus Kohler
markus_kohler at hp.com
Fri Apr 30 03:31:51 EDT 1999
>>>>> "Mitchell" == Mitchell Morris <mgm at unpkhswm04.bscc.bls.com> writes:
[deletia]
Mitchell> If it's not too much trouble, could you post your
Mitchell> benchmark code and results, either here or on a web
Mitchell> page?
Of course I only did useless microbenchmarks ;-)
One was :
# benchmark in Python
# see <url:http://www.lib.uchicago.edu/keith/crisis/benchmarks/tak/>
# Keith Waclena <k-waclena at uchicago.edu>
def tak (x, y, z):
if not(y < x):
return z
else:
return tak(tak(x-1, y, z), tak(y-1, z, x), tak(z-1, x, y))
this is usally a pretty good tests of function call speed.
Since in Smalltalk really everything is object oriented I could not
just define a global function that is not a method of some class.
Therefore I decided to use class methods and introduce a class TestRec
just for that :
takx: x y: y z:z
"Test function call speed"
^(y<x) ifFalse: [z]
ifTrue: [TestRec takx: (TestRec takx:(x-1)y: y z:z) y: (TestRec takx:(y-1) y:z z: x ) z:(TestRec takx:(z-1)y:x z: y)]
I don't have the exact numbers anymore but the latest version of python was about 3 times slower than squeak.
Other things I tested were simple loops like this :
#!/usr/local/bin/python
import time;
def counter():
i = 0;
start = time.time();
for i in range(10000):
j = 0.0;
for k in range(100):
j = j * k;
return time.time() - start;
print counter();
Even Smalltalk's loops are more powerfull than pythons "for" loop, the result
was almost the same as for tak.
Markus
--
Markus Kohler mailto:markus_kohler at hp.com
More information about the Python-list
mailing list