Title: Convenience API for timeit.main
Type: enhancement Stage: needs patch
Components: Library (Lib) Versions: Python 3.2
Status: closed Resolution: duplicate
Dependencies: Superseder: timeit called from within Python should allow autoranging
View: 6422
Assigned To: Nosy List: eli.bendersky, ncoghlan, pitrou, rhettinger, ssapin
Priority: normal Keywords: easy

Created on 2009-03-08 06:02 by ncoghlan, last changed 2012-06-26 12:45 by ncoghlan. This issue is now closed.

Messages (4)
msg83305 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2009-03-08 06:02
For quick and dirty benchmarking, timeit.main() is one of the handiest
tools out there, but calling it from Python code is a little tedious
since you need to construct a fake list of command line arguments in
order to call it.

What would be nice is a convenience function that accepted appropriate
arguments, with timeit.main being refactored to parse the command line
arguments and then call the new convenience function.

Possible API:

def measure(stmt="pass", setup="pass", timer=default_timer,
            repeat=default_repeat, number=default_number,
            verbosity=0, precision=3)

The new function would cover the latter section of the current main()
function, starting from the line "t = Timer(stmt, setup, timer)".
msg83309 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-03-08 13:07
It would be even better if you could pass a locals or globals
dictionnary instead of the "setup" arg.
And even even better if it could implicitly get the locals/globals from
the calling frame :-)
msg85688 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-04-07 06:47
See related discussion in issue 2527 and issue 1397474.
msg164069 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-06-26 12:28
Close in favour of #6422 - that one at least has a patch :)
Date User Action Args
2012-06-26 12:45:22ncoghlansetstatus: open -> closed
2012-06-26 12:28:00ncoghlansetsuperseder: timeit called from within Python should allow autoranging
resolution: duplicate
messages: + msg164069
2012-01-09 11:11:15ssapinsetnosy: + ssapin
2011-07-24 03:08:21eli.benderskysetnosy: + eli.bendersky
2010-08-09 04:12:33terry.reedysetversions: + Python 3.2, - Python 3.1, Python 2.7
2009-04-07 06:47:33rhettingersetassignee: rhettinger ->
messages: + msg85688
2009-03-09 05:29:39rhettingersetassignee: rhettinger

nosy: + rhettinger
2009-03-08 13:07:20pitrousetnosy: + pitrou
messages: + msg83309
2009-03-08 06:02:23ncoghlancreate