{"id":15911535,"url":"https://github.com/nok/tic-toc","last_synced_at":"2025-04-03T02:22:50.895Z","repository":{"id":57475410,"uuid":"154013516","full_name":"nok/tic-toc","owner":"nok","description":"Measure and track the wall and CPU time of defined scopes.","archived":false,"fork":false,"pushed_at":"2018-12-02T22:33:18.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-11-12T09:27:59.911Z","etag":null,"topics":["python","time","timeit","utils"],"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/nok.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-21T13:50:57.000Z","updated_at":"2019-01-03T15:43:20.000Z","dependencies_parsed_at":"2022-09-07T17:02:19.522Z","dependency_job_id":null,"html_url":"https://github.com/nok/tic-toc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nok%2Ftic-toc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nok%2Ftic-toc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nok%2Ftic-toc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nok%2Ftic-toc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nok","download_url":"https://codeload.github.com/nok/tic-toc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246923000,"owners_count":20855514,"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","time","timeit","utils"],"created_at":"2024-10-06T15:42:33.195Z","updated_at":"2025-04-03T02:22:50.868Z","avatar_url":"https://github.com/nok.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tic-toc\n\n[![PyPI](https://img.shields.io/pypi/v/tic-toc.svg)](https://pypi.python.org/pypi/tic-toc)\n[![PyPI](https://img.shields.io/pypi/pyversions/tic-toc.svg)](https://pypi.python.org/pypi/tic-toc)\n[![GitHub license](https://img.shields.io/pypi/l/tic-toc.svg)](https://raw.githubusercontent.com/nok/tic-toc/master/license.txt)\n\nMeasure and track the wall and CPU time of defined scopes in Python.\u003cbr\u003eIt's suitable for long-running applications which should be monitored.\n\n\n## Installation\n\n```bash\n$ pip install tic-toc\n```\n\n\n## Usage\n\nThe following examples demonstrate the most simple usage:\n\nHere you see the implicit variant with the `with` construct:\n\n```python\nfrom tic_toc import Timer\n\nwith Timer('NAME') as timer:\n    print('Scope: ' + timer.name)\n    time.sleep(1)\n```\n\nHere you see the explicit variant without the `with` construct:\n\n```python\nfrom tic_toc import Timer\n\ntimer = Timer('NAME')\ntimer.tic()  # or .start()\nprint('Scope: ' + timer.name)\ntime.sleep(1)\ntimer.toc()  # or .end()\n```\n\nThe outputs are similar to each other:\n\n```python\n# \u003e NAME ...\n# Scope: NAME\n# \u003c NAME [WALL: 1.0034s] [CPU: 0.0001s]\n```\n\nYou can find more extended examples (e.g. with `logging`, `tqdm` or `pandas`) in the [examples](examples) directory.\n\n\n## Parameters\n\n```python\nclass Timer(object):\n    def __init__(self, name: str = None,\n                 format_start: str = '\u003e {name} ...',\n                 format_end: str = '\u003c {name} [WALL: {time_wall:.4f}s] [CPU: {time_cpu:.4f}s]',\n                 to: Callable[[Any], None] = lambda msg: print(msg)):\n```\n\n- `name`: str, optional, default: leading hash with four random digits, eg. `#0512`\n- `format_start`: str, optional, default: `'\u003e {name} ...'`\n- `format_end`: str, optional, default: `'\u003c {name} [WALL: {time_wall:.4f}s] [CPU: {time_cpu:.4f}s]'`\n- `to`: `Callable[[Any], None]`, optional, default: `lambda msg: print(msg)`\n\nYou can change the visual string formats and the output method.\n\n\n## Sources\n\n- [Answer](https://stackoverflow.com/a/5849861/1293700) by Eli Bendersky to the question '[tic, toc functions analog in Python](https://stackoverflow.com/questions/5849800/tic-toc-functions-analog-in-python)'\n- [Python Clocks Explained](https://www.webucator.com/blog/2015/08/python-clocks-explained/) by Nat Dunn\n- [Python 3.7 perf_counter() nanoseconds](https://vstinner.github.io/python37-perf-counter-nanoseconds.html) by Victor Stinner\n- [PEP 564: New Time Functions With Nanosecond Resolution](https://docs.python.org/3.7/whatsnew/3.7.html#pep-564-new-time-functions-with-nanosecond-resolution)\n- [PEP 560: Core Support for typing module and Generic Types](https://docs.python.org/3.7/whatsnew/3.7.html#pep-560-core-support-for-typing-module-and-generic-types)\n- [Slow and fast methods for generating random integers in Python](https://eli.thegreenplace.net/2018/slow-and-fast-methods-for-generating-random-integers-in-python/) by  Eli Bendersky\n\n\n## License\n\nThe module is Open Source Software released under the [MIT](license.txt) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnok%2Ftic-toc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnok%2Ftic-toc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnok%2Ftic-toc/lists"}