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

Posted 冯俊杰

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python--33 像一个极客去思考相关的知识,希望对你有一定的参考价值。

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 像一个极客去思考的主要内容,如果未能解决你的问题,请参考以下文章

像一名教育者一样思考代码质量

c_cpp 加载源图像固定用法(代码片段,不全)

来自极客头条的 35 个 Java 代码性能优化总结

像 C 一样快,Ruby 般丝滑的 Crystal 发布 1.0 版本,你看好吗? | 极客分享第 24 期

常用python日期日志获取内容循环的代码片段

网易极客战记官方攻略-地牢-敌人的陷阱