py-timer


Namepy-timer JSON
Version 1.2.3 PyPI version JSON
download
home_pagehttps://github.com/qfcy/Python/blob/main/timer.py
SummaryA Python timer module, containing class Timer() and decorator function timer(), as well as some useful related functions, can be used for program performance analysis.一个Python计时器模块, 其中包含Timer()类和timer()装饰器, 以及一些有用的相关函数, 可用于程序性能分析。
upload_time2024-01-09 12:03:34
maintainer
docs_urlNone
author七分诚意 qq:3076711200
requires_python
license
keywords timer performance analysis 计时器 性能
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            模块名称 MODULE NAME
====================

::

	timer

简介 DESCRIPTION
================

::

	A Python timer module, containing class Timer() and decorator function timer(), 
	as well as some useful related functions, can be used for program performance analysis.
	一个Python计时器模块, 其中包含Timer()类和timer()装饰器, 以及一些有用的相关函数, 可用于程序性能分析。

包含的函数和类 Functions & Classes:
===================================

类:

class Timer
"""""""""""
	一个计时器类
	
	start()
		开始计时。此方法在Timer类初始化时会被自动调用。
	
	gettime()
		获取从计时开始到现在的时间。
	
	printtime(fmt_str="用时:{:.8f}秒")
		打印出从计时开始到现在的时间, 也就是获取的值。

函数: 

timer(msg=None, file=sys.stdout, flush=False)::

	一个装饰器, 为某个函数计时 (比使用Timer类更快、更简单)。
	用法:@timer(msg="用时:{time}秒")
	def func(args):
		print("Hello World!")
	
	#或:
	@timer
	def func(args):
		print("Hello World!")

示例代码 EXAMPLES
=================

示例1:

.. code-block:: python

	import timer
	t=timer.Timer() #初始化Timer对象
	do_something()
	t.printtime() #输出执行do_something()所用时间 (也可使用t.gettime()获取所用时间)

示例2:

.. code-block:: python

	#退出with语句时自动打印出所用时间。
	import timer
	with timer.Timer(): #在这里开始计时
		do_something()

示例3:

.. code-block:: python

	# 为某个函数计时
	from timer import timer
	@timer
	def func():
		print("Hello World!")

示例4:

.. code-block:: python

	# 程序精确地延迟一段时间
	from time import sleep
	from timer import sleep as sleep2
	sleep(0.0001)
	sleep2(0.0001)
	# 经测试表明, time模块的sleep()函数与本模块的函数相比, 有明显的延迟

版本 VERSION
============

	1.2.3

作者 AUTHOR
===========

	七分诚意 qq:3076711200 贴吧账号:qfcy\_

	作者CSDN主页: https://blog.csdn.net/qfcy\_
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/qfcy/Python/blob/main/timer.py",
    "name": "py-timer",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "timer,performance,analysis,\u8ba1\u65f6\u5668,\u6027\u80fd",
    "author": "\u4e03\u5206\u8bda\u610f qq:3076711200",
    "author_email": "3076711200@qq.com",
    "download_url": "https://files.pythonhosted.org/packages/c1/c5/5ae512df5b66f6b34b93fc356bb07ec2a884b3951fff67d05226ee658fce/py-timer-1.2.3.tar.gz",
    "platform": null,
    "description": "\u6a21\u5757\u540d\u79f0 MODULE NAME\r\n====================\r\n\r\n::\r\n\r\n\ttimer\r\n\r\n\u7b80\u4ecb DESCRIPTION\r\n================\r\n\r\n::\r\n\r\n\tA Python timer module, containing class Timer() and decorator function timer(), \r\n\tas well as some useful related functions, can be used for program performance analysis.\r\n\t\u4e00\u4e2aPython\u8ba1\u65f6\u5668\u6a21\u5757, \u5176\u4e2d\u5305\u542bTimer()\u7c7b\u548ctimer()\u88c5\u9970\u5668, \u4ee5\u53ca\u4e00\u4e9b\u6709\u7528\u7684\u76f8\u5173\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\t\u4e00\u4e2a\u8ba1\u65f6\u5668\u7c7b\r\n\t\r\n\tstart()\r\n\t\t\u5f00\u59cb\u8ba1\u65f6\u3002\u6b64\u65b9\u6cd5\u5728Timer\u7c7b\u521d\u59cb\u5316\u65f6\u4f1a\u88ab\u81ea\u52a8\u8c03\u7528\u3002\r\n\t\r\n\tgettime()\r\n\t\t\u83b7\u53d6\u4ece\u8ba1\u65f6\u5f00\u59cb\u5230\u73b0\u5728\u7684\u65f6\u95f4\u3002\r\n\t\r\n\tprinttime(fmt_str=\"\u7528\u65f6:{:.8f}\u79d2\")\r\n\t\t\u6253\u5370\u51fa\u4ece\u8ba1\u65f6\u5f00\u59cb\u5230\u73b0\u5728\u7684\u65f6\u95f4, \u4e5f\u5c31\u662f\u83b7\u53d6\u7684\u503c\u3002\r\n\r\n\u51fd\u6570: \r\n\r\ntimer(msg=None, file=sys.stdout, flush=False)::\r\n\r\n\t\u4e00\u4e2a\u88c5\u9970\u5668, \u4e3a\u67d0\u4e2a\u51fd\u6570\u8ba1\u65f6 (\u6bd4\u4f7f\u7528Timer\u7c7b\u66f4\u5feb\u3001\u66f4\u7b80\u5355)\u3002\r\n\t\u7528\u6cd5:@timer(msg=\"\u7528\u65f6:{time}\u79d2\")\r\n\tdef func(args):\r\n\t\tprint(\"Hello World!\")\r\n\t\r\n\t#\u6216:\r\n\t@timer\r\n\tdef func(args):\r\n\t\tprint(\"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\timport timer\r\n\tt=timer.Timer() #\u521d\u59cb\u5316Timer\u5bf9\u8c61\r\n\tdo_something()\r\n\tt.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\t#\u9000\u51fawith\u8bed\u53e5\u65f6\u81ea\u52a8\u6253\u5370\u51fa\u6240\u7528\u65f6\u95f4\u3002\r\n\timport timer\r\n\twith timer.Timer(): #\u5728\u8fd9\u91cc\u5f00\u59cb\u8ba1\u65f6\r\n\t\tdo_something()\r\n\r\n\u793a\u4f8b3:\r\n\r\n.. code-block:: python\r\n\r\n\t# \u4e3a\u67d0\u4e2a\u51fd\u6570\u8ba1\u65f6\r\n\tfrom timer import timer\r\n\t@timer\r\n\tdef func():\r\n\t\tprint(\"Hello World!\")\r\n\r\n\u793a\u4f8b4:\r\n\r\n.. code-block:: python\r\n\r\n\t# \u7a0b\u5e8f\u7cbe\u786e\u5730\u5ef6\u8fdf\u4e00\u6bb5\u65f6\u95f4\r\n\tfrom time import sleep\r\n\tfrom timer import sleep as sleep2\r\n\tsleep(0.0001)\r\n\tsleep2(0.0001)\r\n\t# \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\t1.2.3\r\n\r\n\u4f5c\u8005 AUTHOR\r\n===========\r\n\r\n\t\u4e03\u5206\u8bda\u610f qq:3076711200 \u8d34\u5427\u8d26\u53f7:qfcy\\_\r\n\r\n\t\u4f5c\u8005CSDN\u4e3b\u9875: https://blog.csdn.net/qfcy\\_",
    "bugtrack_url": null,
    "license": "",
    "summary": "A Python timer module, containing class Timer() and decorator function timer(), as well as some useful related functions, can be used for program performance analysis.\u4e00\u4e2aPython\u8ba1\u65f6\u5668\u6a21\u5757, \u5176\u4e2d\u5305\u542bTimer()\u7c7b\u548ctimer()\u88c5\u9970\u5668, \u4ee5\u53ca\u4e00\u4e9b\u6709\u7528\u7684\u76f8\u5173\u51fd\u6570, \u53ef\u7528\u4e8e\u7a0b\u5e8f\u6027\u80fd\u5206\u6790\u3002",
    "version": "1.2.3",
    "project_urls": {
        "Homepage": "https://github.com/qfcy/Python/blob/main/timer.py"
    },
    "split_keywords": [
        "timer",
        "performance",
        "analysis",
        "\u8ba1\u65f6\u5668",
        "\u6027\u80fd"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c1c55ae512df5b66f6b34b93fc356bb07ec2a884b3951fff67d05226ee658fce",
                "md5": "aa2cf0ce3ec7eb6d59c74f55f719da7e",
                "sha256": "ef4d062a21d0b5659288b7c8c0aaa0431513264a09a90ef14da964b0f63e4e15"
            },
            "downloads": -1,
            "filename": "py-timer-1.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "aa2cf0ce3ec7eb6d59c74f55f719da7e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4027,
            "upload_time": "2024-01-09T12:03:34",
            "upload_time_iso_8601": "2024-01-09T12:03:34.279648Z",
            "url": "https://files.pythonhosted.org/packages/c1/c5/5ae512df5b66f6b34b93fc356bb07ec2a884b3951fff67d05226ee658fce/py-timer-1.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-09 12:03:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "qfcy",
    "github_project": "Python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "py-timer"
}
        
Elapsed time: 0.16346s