profileit.py

Go to the documentation of this file.
00001 import hotshot, hotshot.stats
00002  
00003 def profileit(printlines=1):
00004     def _my(func):
00005         def _func(*args, **kargs):
00006             prof = hotshot.Profile("profiling.data")
00007             res = prof.runcall(func, *args, **kargs)
00008             prof.close()
00009             stats = hotshot.stats.load("profiling.data")
00010             stats.strip_dirs()
00011             stats.sort_stats('time', 'calls')
00012             print ">>>---- Begin profiling print"
00013             stats.print_stats(printlines)
00014             print ">>>---- End profiling print"
00015             return res
00016         return _func
00017     return _my
00018 
00019 if __name__ == '__main__':
00020     from random import random
00021     def mip():
00022         return random()
00023     @profileit(20)
00024     def mop():
00025         a = 0
00026         for i in xrange(1000):
00027             a += mip()
00028         return a
00029     print mop()
00030 
00031 

© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved; If you reference this document or any part of this document you must use the citation verbatim (including the link) "© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved."

Notice: This source code contained in this document is NOT open source and is NOT being distributed as open source.

122,241 lines of code and growing...