irfpy.util.profile

A simple decorator for profiling.

Code author: Yoshifumi Futaana

This is based on the implementation of Expert Python Programming by Tarek Ziade. Code referred from p.330 in Japanese translation.

How to profile a function

import time
def med():
    time.sleep(0.01)

def lgt():
    time.sleep(0.001)

def hvy():
    print 'heavy process...'
    for i in range(100):
        lgt()
        med()
        med()
    time.sleep(0.5)

@profile('A test for main', list=6)
def main():
        for i in range(2):
            hvy()

print 'Using as a decorator'
main()

print 'Using as a normal function'
p = profile()(med)
p()

See sample/snippet/profile_sample.py

irfpy.util.profile.profile(name='profile', column='time', list=5)[source]
irfpy.util.profile.doctests()[source]