Python threading (was: Re: global interpreter lock not working as it should)

Robin Becker robin at jessikat.fsnet.co.uk
Sat Aug 3 12:20:08 CEST 2002


Are the machine speeds comparable? I tested single thread speed as well
on two freeBSDs with a speed diff around 6.5 for single thread I see
only a factor of 2 in threads.

On my 200Mhz freeBSD 4.5 with python 2.1 I get

# python tspeed.py 10000000
n=10000000 s=10000000 t=132.447

# python threads.py
Counts:
[18517, 13639, 8399, 5760, 5757, 5746, 5739, 5731, 5724, 5718]
Total = 80730

Switches:
[5766, 5765, 5765, 5760, 5757, 5746, 5739, 5731, 5724, 5718]
Total = 57471

on our ISP hosted machine running FreeBSD 4.1.1-STABLE I see

bash-2.04$ python tspeed.py 10000000
n=10000000 s=10000000 t=19.778

bash-2.04$ python threads.py
Counts:
[364324, 154922, 14009, 14005, 14001, 13996, 13993, 13989, 13985, 13981]
Total = 631205

Switches:
[14011, 14012, 14007, 14004, 14001, 13996, 13993, 13989, 13985, 13981]
Total = 139979


#tspeed.py is
import time, sys
try:
    n = int(sys.argv[1])
except:
    n = 100000

def f(a,b):
    return a+b

t0 = time.time()
s = 0
for i in xrange(n):
    s = f(1,s)
t1 = time.time()
print "n=%d s=%d t=%.3f" % (n, s, t1-t0)


-- 
Robin Becker



More information about the Python-list mailing list