[Python-Dev] talking about performance...

Fredrik Lundh Fredrik Lundh" <effbot@telia.com
Sun, 18 Jun 2000 21:06:45 +0200


consider this little program:

import time, sre

k =3D u"foo"
p =3D sre.compile(k)
s =3D "*"*500 + k + "*"*500

def f1():
    p.search(s)

def f2():
    s.find(k)

def bench(f):
    t0 =3D time.clock()
    for i in range(100000):
        f()
    print f, time.clock() - t0

bench(f1)
bench(f2)

which prints:

    <function f1 at 7a0680> 2.94704487169
    <function f2 at 7a06a0> 10.5247875425

(Windows 95, 233 MHz)

if I change the k variable to an 8-bit string, it
prints:

    <function f1 at 7a0740> 2.47613520173
    <function f2 at 7a0760> 2.5178698939

(for some reason, sre is still slighty faster...)

so in other words, something in unicode land isn't
as efficient as it should...

</F>