{"id":28488655,"url":"https://github.com/gusye1234/tiner","last_synced_at":"2025-07-03T18:32:12.408Z","repository":{"id":60484184,"uuid":"543454692","full_name":"gusye1234/tiner","owner":"gusye1234","description":"Block-wise, loop-cumulative timer for Python","archived":false,"fork":false,"pushed_at":"2023-06-24T03:06:03.000Z","size":35,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-08T05:45:08.491Z","etag":null,"topics":["python-library","timer-application"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gusye1234.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-30T06:12:16.000Z","updated_at":"2024-10-26T14:23:12.000Z","dependencies_parsed_at":"2022-09-30T07:10:10.516Z","dependency_job_id":null,"html_url":"https://github.com/gusye1234/tiner","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/gusye1234/tiner","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gusye1234%2Ftiner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gusye1234%2Ftiner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gusye1234%2Ftiner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gusye1234%2Ftiner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gusye1234","download_url":"https://codeload.github.com/gusye1234/tiner/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gusye1234%2Ftiner/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263379266,"owners_count":23457824,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python-library","timer-application"],"created_at":"2025-06-08T05:35:15.916Z","updated_at":"2025-07-03T18:32:12.400Z","avatar_url":"https://github.com/gusye1234.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003etiner\u003c/h1\u003e\n  \u003cp\u003e\u003cstrong\u003eBlock-wise, thread-safety timer for loops\u003c/strong\u003e\u003c/p\u003e\n    \u003cp\u003e\n    \u003ca href=\"https://github.com/gusye1234/tiner/actions?query=workflow%3Atest\"\u003e\n      \u003cimg src=\"https://github.com/gusye1234/tiner/actions/workflows/main.yml/badge.svg\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/gusye1234/tiner\"\u003e\n      \u003cimg src=\"https://img.shields.io/codecov/c/github/gusye1234/tiner\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/tiner/\"\u003e\n      \u003cimg src=\"https://img.shields.io/pypi/v/tiner.svg\"\u003e\n    \u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n\n## Install\n\n```shell\npip install tiner\n```\n\n## Usage\n\n### Works like a context manager\n\n```python\nfrom tiner import tiner\nfrom time import sleep\n\nwith tiner(\"see this block\"):\n  sleep(1)\n# return the block running time\nprint(tiner.get('see this block'))\n```\n\nor as a python decorator\n\n```python\n@tiner('see this function')\ndef f():\n  #do something\n```\n\n### Global mining and grouping\n\nthe timing is managed by `tiner`, not its instances:\n\n```python\n# A.py\nfor _ in range(20):\n  with tiner(\"t1\"):\n    #do something\n...\n# B.py\nfor _ in range(20):\n  with tiner(\"t2\"):\n    #do something\n...\n# main.py\ntiner.table()\n#-------------------------\n╒═════════╤═══════════╤════════╕\n│ Block   │   Time(s) │   Hits │\n╞═════════╪═══════════╪════════╡\n│ t1      │ 0.026127  │     20 │\n├─────────┼───────────┼────────┤\n│ t2      │ 0.0131467 │     10 │\n╘═════════╧═══════════╧════════╛\n```\n\n`tiner` internally records the different locations for the same block name and will merge their duration at report. Display the additional infomation with `tiner.table(verbose=True)`:\n\n```python\nfor _ in range(10):\n  with tiner(\"test:loop\"):\n    sleep(duration)\n  ...\n  with tiner(\"test:loop\"):\n    sleep(duration)\n  \ntiner.table(verbose=True)\n#-------------------------\ntest:loop\n╒═════════════════════╤════════╤═══════════╤════════╕\n│ File                │   Line │   Time(s) │   Hits │\n╞═════════════════════╪════════╪═══════════╪════════╡\n│ tests/test_tiner.py │    107 │ 0.0128279 │     10 │\n├─────────────────────┼────────┼───────────┼────────┤\n│ tests/test_tiner.py │    112 │ 0.0132992 │     10 │\n╘═════════════════════╧════════╧═══════════╧════════╛\n```\n\n### Design for loops\n\n```python\nfrom tiner import tiner\nfrom time import sleep\n\nfor _ in range(10):\n  #do something\n  with tiner(\"see this loop\"):\n    sleep(0.1)\n  #do something\n  \n# return the block running time over the loops\nprint(tiner.get('see this loop'))\n```\n\n### Handle asynchronous programs\n\n```python\nimport os\nfrom tiner import tiner\n\n# tiner will call the synchronize function when the block is over\nwith tiner(\"loop\", synchronize=torch.cuda.synchronize):\n  # machine learning running\n  \n# return the block running time over the loops\nprint(tiner.get('loop'))\n```\n\n### Easy to use\n\nA timer should be clear and simple\n\n```python\ntiner.get(BLOCK_NAME) # return a certain block running time so far\ntiner.table([BLOCK1, ...]) # print some blocks' time on a formatted table\ntiner.zero([BLOCK1, ...]) # empty some blocks' time\ntiner.disable() # disable time logging\ntiner.enable() # enable time logging\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgusye1234%2Ftiner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgusye1234%2Ftiner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgusye1234%2Ftiner/lists"}