From: markus_kohler at hp.com (Markus Kohler)
Date: 30 Apr 1999 09:31:51 +0200
Subject: Python IS slow ! [was] Re: Python too slow for real world
References: <613145F79272D211914B0020AFF6401914DAD8@gandalf.digicool.com> <p5g15lmb35.fsf@bidra241.bbn.hp.com> <slrn7idrvl.kc0.mgm@unpkhswm04.bscc.bls.com>
Message-ID: <p5pv4mlg2g.fsf@bidra241.bbn.hp.com>
Content-Length: 1619
X-UID: 1614                                                  

>>>>> "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




