insomnihack

When sleep eludes, the keyboard beckons

Speed up PyCharm Debugging with Psyco

August 7, 2010 Dale 4 Comments

I’ve been digging what JetBrains is doing with PyCharm, and I’m looking forward to the 1.0 release. Almost everyone doing Python development at work has switched to it. I noticed something a while back that peaked my curiosity, though. While debugging, I came across a cryptic message in PyCharm’s console window:

[text]
pydev debugger: warning: psyco not available for speedups (the debugger will still work correctly, but a bit slower)
[/text]

What’s all this now? Are you saying something on my box isn’t running as fast as it could be? That wouldn’t do at all.

So, I loaded up my web browser. A quick Google search later and I’d found the psyco project on Sourceforge. Psyco is a specialized Python compiler, created by Armin Rigo who is now working on PyPy. Psyco speeds up the execution of most Python programs with a single extension module. Development of psyco was recently taken over by Christian Tismer, who has made many improvements to psyco.

At work, I tend to live in Windows or Ubuntu, and at the moment I was working in Windows, so I followed the link over to Michael Foord’s site where he’d thrown together some 32-bit Windows binaries for psyco 2.0 on Python 2.4, 2.5, and 2.6. I grabbed the 2.6 version, but I didn’t immediately install it.

To gauge the benefit of a psyco-powered debugger versus one without, I first needed to run a baseline benchmark. My work box is a Dell Precision T7400 with an Intel Zeon E5405 @ 2.0Ghz with 8Gb ram on Windows XP SP2 x64. My Python version is 2.6.5 (32-bit – psyco does not as yet work with x64).

I created a new Python project, and copied the pystone.py benchmark file from my Python distribution’s test folder into it. Here’s the results of my first non-psyco debugger run.

[text highlight=”6″]
C:/Tools/Python26/python.exe "C:\Program Files (x86)\JetBrains\PyCharm 96.742\helpers\pydev\pydevd.py" –client 127.0.0.1 –port 13926 –file C:/Source/PsycoTest/pystone.py
Connected to pydevd (version 1.1)
pydev debugger: warning: psyco not available for speedups (the debugger will still work correctly, but a bit slower)
pydev debugger: starting
Pystone(1.1) time for 50000 passes = 8.70703
This machine benchmarks at 5742.49 pystones/second

Process finished with exit code 0
[/text]

Next, I installed psyco and ran the test again.

[text highlight=”5″]
C:/Tools/Python26/python.exe "C:\Program Files (x86)\JetBrains\PyCharm 96.742\helpers\pydev\pydevd.py" –client 127.0.0.1 –port 13936 –file C:/Source/PsycoTest/pystone.py
Connected to pydevd (version 1.1)
pydev debugger: starting
Pystone(1.1) time for 50000 passes = 5.49379
This machine benchmarks at 9101.18 pystones/second

Process finished with exit code 0
[/text]

Not too shabby. My pystone benchmark went from 5742.49 to 9101.18: a 63% improvement just by installing a Python library! Clearly I’m going to have to experiment using psyco for some of my own projects.

Programming PyCharm, Python, tools

Run Coverage.py under PyCharm

July 18, 2010 Dale Leave a Comment

PyCharm‘s test runner does not currently support running Ned Batchelder’s excellent Python code coverage tool coverage.py. While this may be addressed before final release, you can easily set up a run/debug configuration manually to get the same effect. From within PyCharm, select the Run -> Edition Configurations menu item.

Coverage.py Configuration

Coverage.py Configuration

In the Run/Debug Configurations dialog, click the box with the plus sign in the upper right corner to create a new Python script configuration. Call the configuration whatever you want. I tend to run coverage.py as part of nose, so I enter the path to the nosetests-script.py on my file system in the Script field. Under Windows, this will be in the Scripts sub-directory of your Python installation directory. If you’re on Linux or OSX, you can use the nose/core.py file in your site-packages folder.

In the Script parameters field, I enter the --with-coverage and --cover-package command line parameters. Finally, in the Working directory field, I add the path to the directory containing my unit tests. Running this configuration executes code coverage on my unit test directory, and PyCharm is smart enough to recognize any stack traces that may occur during the run, providing click-able links to the offending lines of code.

Programming PyCharm, Python, tools, unit tests

About Me

Hi, my name's Dale, and this is my tech blog. Read More…

Search

Tags

blogging c# database Django documentation Email furniture git hacks htpc IPython Linux mac nas packaging PyCharm Python Roleplaying tools twitter unit tests virtualenv Visual Studio vmware Windows

Copyright © 2025 · Equilibre Theme on Genesis Framework · WordPress · Log in