This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gvanrossum
Recipients dmoore, ezio.melotti, georg.brandl, giampaolo.rodola, gvanrossum, ncoghlan, rhettinger, steven.daprano, tim.peters
Date 2014-06-16.02:59:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1402887572.77.0.415408744294.issue19495@psf.upfronthosting.co.za>
In-reply-to
Content
I agree with Raymond -- this is a common pattern but there are many variations that are hard to catch in a single implementation. E.g. at Dropbox we have a decorator like this that lets you specify an identifier for the block you name, and which logs the measured times to a special log file. Then there is separate analysis software that shows the plots the average time for each named block over time. Incredibly useful, but hard to share the code.

I think that Jeff Preshing's blog post giving the basic idea (to which Steven's recipe links) is more useful than a implementation in the stdlib could ever be. Steven's class already has three keyword arguments, and that feels like either not enough or already too many, depending on your needs. It's too easy to bikeshed it to death. (E.g. the "disable+restore gc" feature could easily be moved into a separate decorator; and why not make the verbose printing a little more flexible by adding another parameter to either specify the file to print to or the function to be used to print. Oh, and the message could be customizable. Then again, you might want to subclass this in order to do all those customizations, eventually allowing this to be used as the basis for e.g. the Dropbox version. Etc. Not that I propose to go that way -- I'm just bringing this up to indicate how hopeless it would be to try and put some version in the stdlib.)
History
Date User Action Args
2014-06-16 02:59:32gvanrossumsetrecipients: + gvanrossum, tim.peters, georg.brandl, rhettinger, ncoghlan, giampaolo.rodola, ezio.melotti, steven.daprano, dmoore
2014-06-16 02:59:32gvanrossumsetmessageid: <1402887572.77.0.415408744294.issue19495@psf.upfronthosting.co.za>
2014-06-16 02:59:32gvanrossumlinkissue19495 messages
2014-06-16 02:59:31gvanrossumcreate