Steven D'Aprano added the comment:

This issue seems to have lost momentum, I'd like to revive it by proposing a 
slightly different interface for the autorange function.

Attached is a proof-of-concept patch. I've moved the code which determines the 
number of loops out of the main function into a new Timer method, 
``autorange``. The main difference between my approach and Scott's is that my 
autorange method doesn't do any printing directly, it takes an optional 
callback function. This lets the caller take responsibility for all output.

If this approach is acceptable, I hope to:

- (in 3.6) add tests and docs for the new method;

- (in 3.6 if time permits, otherwise 3.7) modify the timeit and repeat methods 
and functions so that they can optionally call autorange(), e.g. if the caller 
passes 0 as the number.

I'm not sure that there's a good reason to add a top-level autorange() function 
to match the timeit() and repeat() functions. Especially not once they gain the 
ability to autorange themselves.

I think my approach will be compatible with cleaning up and refactoring the 
main() function. At the moment, main() is a mess IMO, it handles argument 
processing, autoranging, units of time, and unreliable timing detection all 
from one function.

----------
nosy: +steven.daprano
versions: +Python 3.6 -Python 3.5
Added file: http://bugs.python.org/file42816/timeit-autorange.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue6422>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to