timer

Python code timer, support block wise and function wise

https://github.com/lucienshui/timer

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (5.4%) to scientific vocabulary

Keywords

python timer
Last synced: 6 months ago · JSON representation

Repository

Python code timer, support block wise and function wise

Basic Info
Statistics
  • Stars: 16
  • Watchers: 2
  • Forks: 2
  • Open Issues: 2
  • Releases: 10
Topics
python timer
Created over 5 years ago · Last pushed almost 2 years ago
Metadata Files
Readme License

README.md

Timer

Python code timer, support block wise and function wise

Installation

shell pip install timer

Usage

  1. import py from timer import timer

  2. decorate without brackets py @timer def func(): ...

  3. decorate with brackets py @timer() def func(): ...

  4. decorate with name and time unit py @timer('function name', 's') def func(): ...

  5. decorate with key word arguments py @timer(name='function name', unit='s') def func(): ...

  6. block wise without object

    py with timer(): ...

  7. block wise with object

    py with timer() as t: ... print(t.elapse)

Sample Code

```python import logging import time

from timer import timer, get_timer

default timer's logging level is logging.DEBUG

so timer would print nothing if logging level is logging.INFO or higher

logging.basicConfig(level=logging.DEBUG)

or you can change default timer's logging level

timer.set_level(logging.DEBUG)

also you can get a timer with custom logging level with get_timer(level)

warningtimer = gettimer(logging.WARNING)

explicit the timer's name and it's time unit

@timer('function:add', unit='s') def add(a, b): time.sleep(.1) return a + b

function name is timer's name for default

@timer def sub(a, b): time.sleep(.1) return a - b

if name == 'main': # 'timer' would be timer's name by default with timer('time.sleep(2)') as t: print(3) time.sleep(1) print(f'after time.sleep(1) once, t.elapse = {t.elapse}') time.sleep(1) print(f'after time.sleep(1) twice, t.elapse = {t.elapse}') print(f'after with, t.elapse = {t.elapse}')

with warning_timer('test'):
   pass

print(add(1, 1))
print(sub(2, 1))

```

Outputs

plain 3 after time.sleep(1) once, t.elapse = 1.003798776 after time.sleep(1) twice, t.elapse = 2.0052743459999998 DEBUG:timer.time.sleep(2): 2.006 s after with, t.elapse = 2.005628447 WARNING:timer.test:start WARNING:timer.test:cost 0 ms DEBUG:timer.function:add: 0.105 s 2 DEBUG:timer.sub: 102 ms 1

Special Thanks

@Krzysztof S

Owner

  • Name: Lucien
  • Login: LucienShui
  • Kind: user
  • Location: Hangzhou
  • Company: @alibaba

因为孤独是人之常态,所以陪伴才显得尤为珍贵。

GitHub Events

Total
  • Watch event: 1
Last Year
  • Watch event: 1

Committers

Last synced: almost 3 years ago

All Time
  • Total Commits: 23
  • Total Committers: 1
  • Avg Commits per committer: 23.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Lucien Shui l****n@l****k 23
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 3
  • Total pull requests: 10
  • Average time to close issues: about 6 hours
  • Average time to close pull requests: about 2 months
  • Total issue authors: 3
  • Total pull request authors: 2
  • Average comments per issue: 0.67
  • Average comments per pull request: 0.3
  • Merged pull requests: 9
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • crowmagnumb (1)
  • christophevg (1)
  • furechan (1)
Pull Request Authors
  • LucienShui (9)
  • christophevg (1)
Top Labels
Issue Labels
bug (1)
Pull Request Labels
documentation (4) chore (3) bug (1) enhancement (1)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 11,673 last-month
  • Total docker downloads: 149
  • Total dependent packages: 2
  • Total dependent repositories: 65
  • Total versions: 9
  • Total maintainers: 2
pypi.org: timer

Python Code Timer

  • Versions: 9
  • Dependent Packages: 2
  • Dependent Repositories: 65
  • Downloads: 11,673 Last month
  • Docker Downloads: 149
Rankings
Downloads: 1.8%
Dependent repos count: 1.8%
Docker downloads count: 3.1%
Dependent packages count: 3.1%
Average: 7.4%
Stargazers count: 15.2%
Forks count: 19.1%
Maintainers (2)
Last synced: 6 months ago

Dependencies

.github/workflows/python-publish.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
.github/workflows/release-drafter.yml actions
  • release-drafter/release-drafter v5 composite
setup.py pypi