码迷,mamicode.com
首页 > 编程语言 > 详细

Python--33 像一个极客去思考

时间:2017-09-14 16:28:58      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:tab   oba   baseline   rar   least   more   number   --   sel   

Python自带电池

  电池:Python标准库

  PyThon标准库中包含一般任务所需要的模块

  Python documentation

timeit.__doc__

timeid__all__
timeit.__file__

dir(timeit)

help(timeit)

>>> import timeit
>>> print(timeit.__doc__)
Tool for measuring execution time of small code snippets.

This module avoids a number of common traps for measuring execution
times.  See also Tim Peters introduction to the Algorithms chapter in
the Python Cookbook, published by OReilly.

Library usage: see the Timer class.

Command line usage:
    python timeit.py [-n N] [-r N] [-s S] [-t] [-c] [-p] [-h] [--] [statement]

Options:
  -n/--number N: how many times to execute statement (default: see below)
  -r/--repeat N: how many times to repeat the timer (default 3)
  -s/--setup S: statement to be executed once initially (default pass).
                Execution time of this setup statement is NOT timed.
  -p/--process: use time.process_time() (default is time.perf_counter())
  -t/--time: use time.time() (deprecated)
  -c/--clock: use time.clock() (deprecated)
  -v/--verbose: print raw timing results; repeat for more digits precision
  -u/--unit: set the output time unit (usec, msec, or sec)
  -h/--help: print this usage message and exit
  --: separate options from statement, use when statement starts with -
  statement: statement to be timed (default pass)

A multi-line statement may be given by specifying each line as a
separate argument; indented lines are possible by enclosing an
argument in quotes and using leading spaces.  Multiple -s options are
treated similarly.

If -n is not given, a suitable number of loops is calculated by trying
successive powers of 10 until the total time is at least 0.2 seconds.

Note: there is a certain baseline overhead associated with executing a
pass statement.  It differs between versions.  The code here doesnt try
to hide it, but you should be aware of it.  The baseline overhead can be
measured by invoking the program without arguments.

Classes:

    Timer

Functions:

    timeit(string, string) -> float
    repeat(string, string) -> list
    default_timer() -> float


>>> dir(timeit)
[Timer, __all__, __builtins__, __cached__, __doc__, __file__, __loader__, __name__, __package__, __spec__, _globals, default_number, default_repeat, default_timer, dummy_src_name, gc, itertools, main, reindent, repeat, sys, template, time, timeit]
>>> timeit.__all__
[Timer, timeit, repeat, default_timer]
>>> from timeit import *
>>> Timer
<class timeit.Timer>
>>> import timeit
>>> timeit.__file__
/usr/lib64/python3.6/timeit.py
>>> help(timeit)

 

Python--33 像一个极客去思考

标签:tab   oba   baseline   rar   least   more   number   --   sel   

原文地址:http://www.cnblogs.com/fengjunjie-w/p/7520711.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!