模块名称 MODULE NAME
====================
::
timer_tool
简介 DESCRIPTION
================
::
A Python timer module, containing class Timer() and decorator function timer(),
as well as some useful functions that can be used for performance analysis.
一个Python计时器模块, 其中包含Timer()类和timer()装饰器, 以及一些相关的有用函数, 可用于程序性能分析。
包含的函数和类 Functions & Classes:
===================================
类:
class Timer
"""""""""""
一个计时器类。A timer class.
start()
开始计时。此方法在Timer类初始化时会被自动调用。
Start timing. This method will be automatically called when the Timer class is initialized.
gettime()
获取从计时开始到现在的时间。
Get the elapsed time since the timer started.
printtime(fmt_str="用时:{:.8f}秒")
打印出从计时开始到现在的时间, 也就是gettime()获取的值。
Print the time elapsed since the timer started, which is the value obtained from gettime().
函数:
timer(msg=None, file=sys.stdout, flush=False)::
一个装饰器, 为某个函数或生成器计时 (比使用Timer类更简洁)。
A wrapper for timing a function or a generator that is briefer than the Timer class.
用法:@timer(msg="用时:{time}秒")
def func(args):
print("Hello World!")
#或:
@timer
def func(args):
print("Hello World!")
示例代码 EXAMPLES
=================
示例1:
.. code-block:: python
import timer_tool
t=timer.Timer() #初始化Timer对象
do_something()
t.printtime() #输出执行do_something()所用时间 (也可使用t.gettime()获取所用时间)
示例2:
.. code-block:: python
#退出with语句时自动打印出所用时间。
import timer_tool
with timer.Timer(): #在这里开始计时
do_something()
示例3:
.. code-block:: python
# 为某个函数计时
from timer_tool import timer
@timer
def func():
print("Hello World!")
示例4:
.. code-block:: python
# 程序精确地延迟一段时间
from time import sleep
from timer_tool import sleep as sleep2
sleep(0.0001)
sleep2(0.0001)
# 经测试表明, time模块的sleep()函数与本模块的函数相比, 有明显的延迟
版本 VERSION
============
1.2.4
作者 AUTHOR
===========
qfcy (七分诚意) qq:3076711200
作者CSDN主页: https://blog.csdn.net/qfcy\_
Raw data
{
"_id": null,
"home_page": "https://github.com/qfcy/Python/blob/main/timer_tool.py",
"name": "timer-tool",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "timer, performance, analysis, \u8ba1\u65f6\u5668, \u6027\u80fd",
"author": "qfcy qq:3076711200",
"author_email": "3076711200@qq.com",
"download_url": "https://files.pythonhosted.org/packages/dc/2d/dc41b5faf7503d8f7210c52d2ade4d70b9adc65a137ca3f7857efcdef12c/timer-tool-1.2.4.tar.gz",
"platform": null,
"description": "\u6a21\u5757\u540d\u79f0 MODULE NAME\r\n====================\r\n\r\n::\r\n\r\n timer_tool\r\n\r\n\u7b80\u4ecb DESCRIPTION\r\n================\r\n\r\n::\r\n\r\n A Python timer module, containing class Timer() and decorator function timer(), \r\n as well as some useful functions that can be used for performance analysis.\r\n \u4e00\u4e2aPython\u8ba1\u65f6\u5668\u6a21\u5757, \u5176\u4e2d\u5305\u542bTimer()\u7c7b\u548ctimer()\u88c5\u9970\u5668, \u4ee5\u53ca\u4e00\u4e9b\u76f8\u5173\u7684\u6709\u7528\u51fd\u6570, \u53ef\u7528\u4e8e\u7a0b\u5e8f\u6027\u80fd\u5206\u6790\u3002\r\n\r\n\u5305\u542b\u7684\u51fd\u6570\u548c\u7c7b Functions & Classes:\r\n===================================\r\n\r\n\u7c7b:\r\n\r\nclass Timer\r\n\"\"\"\"\"\"\"\"\"\"\"\r\n \u4e00\u4e2a\u8ba1\u65f6\u5668\u7c7b\u3002A timer class.\r\n \r\n start()\r\n \u5f00\u59cb\u8ba1\u65f6\u3002\u6b64\u65b9\u6cd5\u5728Timer\u7c7b\u521d\u59cb\u5316\u65f6\u4f1a\u88ab\u81ea\u52a8\u8c03\u7528\u3002\r\n\t\tStart timing. This method will be automatically called when the Timer class is initialized.\r\n \r\n gettime()\r\n \u83b7\u53d6\u4ece\u8ba1\u65f6\u5f00\u59cb\u5230\u73b0\u5728\u7684\u65f6\u95f4\u3002\r\n\t\tGet the elapsed time since the timer started.\r\n \r\n printtime(fmt_str=\"\u7528\u65f6:{:.8f}\u79d2\")\r\n \u6253\u5370\u51fa\u4ece\u8ba1\u65f6\u5f00\u59cb\u5230\u73b0\u5728\u7684\u65f6\u95f4, \u4e5f\u5c31\u662fgettime()\u83b7\u53d6\u7684\u503c\u3002\r\n\t\tPrint the time elapsed since the timer started, which is the value obtained from gettime().\r\n\r\n\u51fd\u6570: \r\n\r\ntimer(msg=None, file=sys.stdout, flush=False)::\r\n\r\n \u4e00\u4e2a\u88c5\u9970\u5668, \u4e3a\u67d0\u4e2a\u51fd\u6570\u6216\u751f\u6210\u5668\u8ba1\u65f6 (\u6bd4\u4f7f\u7528Timer\u7c7b\u66f4\u7b80\u6d01)\u3002\r\n\tA wrapper for timing a function or a generator that is briefer than the Timer class.\r\n \u7528\u6cd5:@timer(msg=\"\u7528\u65f6:{time}\u79d2\")\r\n def func(args):\r\n print(\"Hello World!\")\r\n \r\n #\u6216:\r\n @timer\r\n def func(args):\r\n print(\"Hello World!\")\r\n\r\n\u793a\u4f8b\u4ee3\u7801 EXAMPLES\r\n=================\r\n\r\n\u793a\u4f8b1:\r\n\r\n.. code-block:: python\r\n\r\n import timer_tool\r\n t=timer.Timer() #\u521d\u59cb\u5316Timer\u5bf9\u8c61\r\n do_something()\r\n t.printtime() #\u8f93\u51fa\u6267\u884cdo_something()\u6240\u7528\u65f6\u95f4 (\u4e5f\u53ef\u4f7f\u7528t.gettime()\u83b7\u53d6\u6240\u7528\u65f6\u95f4)\r\n\r\n\u793a\u4f8b2:\r\n\r\n.. code-block:: python\r\n\r\n #\u9000\u51fawith\u8bed\u53e5\u65f6\u81ea\u52a8\u6253\u5370\u51fa\u6240\u7528\u65f6\u95f4\u3002\r\n import timer_tool\r\n with timer.Timer(): #\u5728\u8fd9\u91cc\u5f00\u59cb\u8ba1\u65f6\r\n do_something()\r\n\r\n\u793a\u4f8b3:\r\n\r\n.. code-block:: python\r\n\r\n # \u4e3a\u67d0\u4e2a\u51fd\u6570\u8ba1\u65f6\r\n from timer_tool import timer\r\n @timer\r\n def func():\r\n print(\"Hello World!\")\r\n\r\n\u793a\u4f8b4:\r\n\r\n.. code-block:: python\r\n\r\n # \u7a0b\u5e8f\u7cbe\u786e\u5730\u5ef6\u8fdf\u4e00\u6bb5\u65f6\u95f4\r\n from time import sleep\r\n from timer_tool import sleep as sleep2\r\n sleep(0.0001)\r\n sleep2(0.0001)\r\n # \u7ecf\u6d4b\u8bd5\u8868\u660e, time\u6a21\u5757\u7684sleep()\u51fd\u6570\u4e0e\u672c\u6a21\u5757\u7684\u51fd\u6570\u76f8\u6bd4, \u6709\u660e\u663e\u7684\u5ef6\u8fdf\r\n\r\n\u7248\u672c VERSION\r\n============\r\n\r\n 1.2.4\r\n\r\n\u4f5c\u8005 AUTHOR\r\n===========\r\n\r\n qfcy (\u4e03\u5206\u8bda\u610f) qq:3076711200\r\n\r\n \u4f5c\u8005CSDN\u4e3b\u9875: https://blog.csdn.net/qfcy\\_\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A Python timer module, containing class Timer() and decorator function timer(), as well as some useful functions that can be used for performance analysis.\u4e00\u4e2aPython\u8ba1\u65f6\u5668\u6a21\u5757, \u5176\u4e2d\u5305\u542bTimer()\u7c7b\u548ctimer()\u88c5\u9970\u5668, \u4ee5\u53ca\u4e00\u4e9b\u76f8\u5173\u7684\u6709\u7528\u51fd\u6570, \u53ef\u7528\u4e8e\u7a0b\u5e8f\u6027\u80fd\u5206\u6790\u3002",
"version": "1.2.4",
"project_urls": {
"Homepage": "https://github.com/qfcy/Python/blob/main/timer_tool.py"
},
"split_keywords": [
"timer",
" performance",
" analysis",
" \u8ba1\u65f6\u5668",
" \u6027\u80fd"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "dc2ddc41b5faf7503d8f7210c52d2ade4d70b9adc65a137ca3f7857efcdef12c",
"md5": "b3d76b0c9d78cd6326ea7004bea026b9",
"sha256": "d6a1d4e133d453c4220018a025c3ae4e18201821d76ccc5205719ca8ace8dd24"
},
"downloads": -1,
"filename": "timer-tool-1.2.4.tar.gz",
"has_sig": false,
"md5_digest": "b3d76b0c9d78cd6326ea7004bea026b9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 15874,
"upload_time": "2024-08-12T12:13:15",
"upload_time_iso_8601": "2024-08-12T12:13:15.391908Z",
"url": "https://files.pythonhosted.org/packages/dc/2d/dc41b5faf7503d8f7210c52d2ade4d70b9adc65a137ca3f7857efcdef12c/timer-tool-1.2.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-12 12:13:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "qfcy",
"github_project": "Python",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "timer-tool"
}