# Psyco testing feed-back wanted

Jimmy Retzlaff jimmy at retzlaff.com
Fri Aug 23 23:52:53 CEST 2002

```Wow!!!

I've seen raves about Psyco, but I hadn't tried it myself until today.
My test case was a function that tests if a point is in a polygon. I
timed several runs with different approaches. All tests are whether 1
point is in a polygon made up of 5,000,000 points. The timing was done
on just the function call itself. Here are some results:

Python (no types declared, floats used) - 14.2 seconds (1x)
Python (no types declared, ints used) - 12.0 seconds (1.2x)
Pyrex (coordinates declared as object, floats used) - 4.8 seconds (3x)
Pyrex (coordinates declared as object, ints used) - 4.7 seconds (3x)
Pyrex (coordinates declared as float) - 2.3 seconds (6x)
Pyrex (coordinates declared as int) - 1.5 seconds (9.5x)
Psyco (no types declared, floats used) - 1.47 (9.5x)
C (coordinates declared as double) - 0.99 seconds (14x)
Psyco (no types declared, ints used) - 0.41 seconds (35x)
C (coordinates declared as unsigned int) - 0.20 seconds (71x)

It's amazing to get this type of code performing this close to C (in
this case VC6 optimized for speed) with no modifications and no type
declarations. For those of you who haven't tried Psycho, here is the
code that had to appear after my function definition:

import psyco
psyco.bind(pointInPolygon)

No other modifications were made to my Python code and Psyco requires no
modification to the Python installation, just drop the Psyco folder into
site-packages. The Python version of the test function is below.

Jimmy

def pointInPolygon((x, y), polygon):
"""Determine if the point (x, y) is in the polygon.

>>> polygon = [(0, 0), (3, 3), (0, 6), (-3, 3)]
>>> pointInPolygon((1, 2), polygon)
1
>>> pointInPolygon((2, 1), polygon)
0
"""

# also appears at http://www.linuxjournal.com/article.php?sid=2029

if len(polygon) < 3:
return False

result = False
xOld, yOld = polygon[-1]
for xNew, yNew in polygon:
if xNew > xOld:
if xOld < x <= xNew and (y-yOld)*(xNew-xOld) <
(yNew-yOld)*(x-xOld):
result = not result
elif xNew < x <= xOld and (y-yNew)*(xOld-xNew) <
(yOld-yNew)*(x-xNew):
result = not result

xOld = xNew
yOld = yNew

return result

```