zopefoundation/ExtensionClass — pull request #1 by davisagli (2013-03-21 05:50:22+00:00)
Title: Add pure-Python reference implementation

This adds a Python reference implementation and tox to run tests of the C implementation on Python 2.6 and 2.7 and the Python implementation on Python 2.7 and PyPy. The Python implementation is used by default on PyPy.

I used the following script to benchmark the improvement in speed when running the Python implementation on PyPy:

## EC.py:

from ExtensionClass import Base

class Foo(Base):
pass

RANGE = 1000000
o = a = Foo()
for x in range(RANGE):
setattr(a, 'a', Foo())
a = a.a

## bash:

# CPython + Python implementation
% time PYTHONPATH=develop/ExtensionClass/src python EC.py
8.08s user 0.30s system 99% cpu 8.456 total

# CPython + C implementation
% time PYTHONPATH=develop/ExtensionClass/src python EC.py
3.80s user 0.26s system 99% cpu 4.081 total

# PyPy + Python implementation
% time PYTHONPATH=develop/ExtensionClass/src pypy EC.py
0.16s user 0.05s system 94% cpu 0.217 total