Skip to main content

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()装饰器, 以及一些相关的有用函数, 可用于程序性能分析。

Project description

警告: 由于本模块的名称timer和pywin32库中的timer模块名称冲突,本模块已弃用和停止更新,请安装作者最新版本的timer-tool模块(https://pypi.org/project/timer-tool/)。

Warning: Due to a naming conflict with the timer module in the pywin32 library, this module has been deprecated and will no longer be maintained. Please install the author’s latest version of module timer-tool (https://pypi.org/project/timer-tool/).

模块名称 MODULE NAME

timer

简介 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

一个计时器类

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:

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

示例2:

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

示例3:

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

示例4:

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

版本 VERSION

1.2.4

警告: 由于本模块的名称timer和pywin32库中的timer模块名称冲突,本模块已弃用和停止更新,请安装作者最新版本的timer-tool模块(https://pypi.org/project/timer-tool/)。

作者 AUTHOR

七分诚意 qq:3076711200

作者CSDN主页: https://blog.csdn.net/qfcy_

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-timer-1.2.4.tar.gz (16.0 kB view details)

Uploaded Source

File details

Details for the file py-timer-1.2.4.tar.gz.

File metadata

  • Download URL: py-timer-1.2.4.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.8

File hashes

Hashes for py-timer-1.2.4.tar.gz
Algorithm Hash digest
SHA256 ef81152b291bd297662f2de8650be3a7b84b12d86bb594e3211271fa99f3436d
MD5 b7cc0c4d54b4e47bc548e7e548777a72
BLAKE2b-256 5bfccf9d7a77c2e656d9c4b3ce28f6ae78c4728b80dbb79a5def13dd4a98493f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page