Donnerstag, 26. April 2007

Python design by contract

Today I've implemented some decorators for Eiffel-like design py contract.
It's very nice to use I think:

@require('s1 != 0')
def inv(s1): return 1/s1

or
@require('x != 0')
@enshure('result > 0')
def quad(x): return x*x*x / x


For more information just ask me. I'll put the code somewhere, soon.

- stanz

Mittwoch, 28. Februar 2007

Profiling Django: hotshot

Today I've discovered an article about profiling Django with hotshot. After some minutes of googling 'hotspot' I recognized my fault and found the right python doc.
As I didn't want to setup my apache just for a little profiling session, I did the following:
to settings.py I've added
import hotshot
PROF = hotshot.Profile("plik.prof")
every view-method that should be profiled got:
from settings import PROF
PROF.start()
(...)
PROF.stop()

and finally this came to my 'viewstat'-view:
import hotshot.stats
stats = hotshot.stats.load("plik.prof")
stats.strip_dirs()
stats.sort_stats('time', 'calls')
stats.print_stats(20)

And that's how I've become happy today. Wish me good luck for my cold.
- baum

It's fair to say that this probably won't run in a production-setup because of multithreading.