Python--33 像一個極客去思考
阿新 • • 發佈:2017-09-14
similar ecif baseline style 一個 trying arguments between mman
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 trapsfor measuring execution times. See also Tim Peters‘ introduction to the Algorithms chapter in the Python Cookbook, published by O‘Reilly. 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 doesn‘t 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 像一個極客去思考