[Python-Dev] Re: marking shared-ness

Christian Tismer tismer@tismer.com
Fri, 21 Apr 2000 22:29:06 +0200


Guido van Rossum wrote:
> 
> > It is more than this. In my last shot at this, pystone ran about half as
> > fast. There are a few things that will be different this time around, but
> > it certainly won't in the "few percent" range.
> 
> Interesting thought: according to patches recently posted to
> patches@python.org (but not yet vetted), "turning on" threads on Win32
> in regular Python also slows down Pystone considerably.  Maybe it's
> not so bad?  Maybe those patches contain a hint of what we could do?

I had a rough look at the patches but didn't understand
enough yet. But I tried the sample scriptlet on python 1.5.2
and Stackless Python - see here:

D:\python>python -c "import test.pystone;test.pystone.main()"
Pystone(1.1) time for 10000 passes = 1.96765
This machine benchmarks at 5082.2 pystones/second

D:\python>python spc/threadstone.py
Pystone(1.1) time for 10000 passes = 5.57609
This machine benchmarks at 1793.37 pystones/second

This is even worse than Markovitch's observation.

Now, let's try with Stackless Python:

D:\python>cd spc

D:\python\spc>python -c "import test.pystone;test.pystone.main()"
Pystone(1.1) time for 10000 passes = 1.843
This machine benchmarks at 5425.94 pystones/second

D:\python\spc>python threadstone.py
Pystone(1.1) time for 10000 passes = 3.27625
This machine benchmarks at 3052.27 pystones/second

Isn't that remarkable? Stackless performs nearly 1.8
as good under threads.

Why?
I've optimized the ticker code away for all those
"fast" opcodes which never can cause another interpreter
incarnation. Standard Python does a bit too much here,
dealing the same way with extremely fast opcodes like POP_TOP,
as with a function call. Responsiveness is still very good.

Markovitch's example also tells us this story:
Even with his patches, the threading stuff still costs
10 percent. This is the lock that we touch every ten
opcodes. In other words: touching a lock costs about
as much as an opcode costs on average.

ciao - chris

threadstone.py:
import thread
# Start empty thread to initialise thread mechanics (and global lock!)
# This thread will finish immediately thus won't make much influence on
# test results by itself, only by that fact that it initialises global lock
thread.start_new_thread(lambda : 1, ())

import test.pystone
test.pystone.main()

-- 
Christian Tismer             :^)   <mailto:tismer@appliedbiometrics.com>
Applied Biometrics GmbH      :     Have a break! Take a ride on Python's
Kaunstr. 26                  :    *Starship* http://starship.python.net
14163 Berlin                 :     PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     where do you want to jump today?   http://www.stackless.com