[Tutor] Generator next()
eryksun
eryksun at gmail.com
Sat Dec 28 11:41:17 CET 2013
On Sat, Dec 28, 2013 at 4:45 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> Anyway, if I'm going to criticise, I ought to show what I consider
> better. Here's a quick and unpolished decorator for instrumenting
> functions. For simplicity, it too will be inaccurate for Windows and
> really fast/small functions, but I reckon this is good enough for a
> first draft.
Use timeit.default_timer. Or just copy how it's defined:
if sys.platform == "win32":
# On Windows, the best timer is time.clock()
default_timer = time.clock
else:
# On most other platforms the best timer is time.time()
default_timer = time.time
In 3.3, it's updated to use time.perf_counter() on all platforms:
http://docs.python.org/3/library/time#time.perf_counter
More information about the Tutor
mailing list