{"id":13501786,"url":"https://github.com/ramonsaraiva/timy","last_synced_at":"2025-03-29T09:31:25.998Z","repository":{"id":57475677,"uuid":"78300913","full_name":"ramonsaraiva/timy","owner":"ramonsaraiva","description":"Minimalist measurement of python code time","archived":false,"fork":false,"pushed_at":"2020-07-17T01:55:52.000Z","size":30,"stargazers_count":276,"open_issues_count":0,"forks_count":13,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-26T13:54:56.233Z","etag":null,"topics":["measurement","python","time","timy"],"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/ramonsaraiva.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-07T20:05:52.000Z","updated_at":"2025-01-31T16:38:44.000Z","dependencies_parsed_at":"2022-09-07T17:11:57.526Z","dependency_job_id":null,"html_url":"https://github.com/ramonsaraiva/timy","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/ramonsaraiva%2Ftimy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramonsaraiva%2Ftimy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramonsaraiva%2Ftimy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramonsaraiva%2Ftimy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ramonsaraiva","download_url":"https://codeload.github.com/ramonsaraiva/timy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246167389,"owners_count":20734381,"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":["measurement","python","time","timy"],"created_at":"2024-07-31T22:01:50.284Z","updated_at":"2025-03-29T09:31:25.614Z","avatar_url":"https://github.com/ramonsaraiva.png","language":"Python","funding_links":[],"categories":["Python","Python Hacks"],"sub_categories":[],"readme":"# timy\n\n![Python 3.4](https://img.shields.io/badge/python-3.4-blue.svg)\n![Python 3.5](https://img.shields.io/badge/python-3.5-blue.svg)\n![Python 3.6](https://img.shields.io/badge/python-3.6-blue.svg)\n![Python 3.7](https://img.shields.io/badge/python-3.7-blue.svg)\n\n![CircleCI](https://img.shields.io/circleci/project/github/ramonsaraiva/timy/master.svg)\n![Codecov](https://img.shields.io/codecov/c/github/ramonsaraiva/timy/master.svg)\n\nMinimalist measurement of python code time\n\u003e **timy** comes with a different idea of the built-in module [timeit](https://docs.python.org/2.7/library/timeit.html). It adds flexibility and different ways of measuring code time, using simple context managers and function decorators.\n\n## Installing\n```\npip install timy\n```\n\n## Usage\n\n### Decorating a function\nLet's say you have a `calculate` function and you want to keep track of its execution time\n```python\nimport timy\n\n@timy.timer()\ndef calculate(n, r):\n    \"\"\"\n    Divide, multiply and sum 'n' to every number in range 'r'\n    returning the result list\n    \"\"\"\n    return [i / n * n + n for i in range(r)]\n```\n\nWhenever you call that function, the execution time will be tracked\n\n```python\ncalculate(5, 10000000)\n\u003e\u003e Timy executed (calculate) for 1 time(s) in 1.529540 seconds\n\u003e\u003e Timy best time was 1.529540 seconds\n```\n\nChanging the **ident** and adding **loops** to the execution\n\n```python\nimport timy\n\n@timy.timer(ident='My calculation', loops=10)\ndef calculate(n, r):\n    return [i / n * n + n for i in range(r)]\n    \ncalculate(5, 10000000)\n\u003e\u003e My calculation executed (calculate) for 10 time(s) in 15.165313 seconds\n\u003e\u003e My calculation best time was 1.414186 seconds\n```\n\n### Tracking **specific points** along your code\nThe `with` statement can also be used to measure code time\n\u003e Named tracking points can be added with the `track` function\n\n```python\nimport timy\n\nwith timy.Timer() as timer:\n    N = 10000000\n    for i in range(N):\n        if i == N/2:\n            timer.track('Half way')\n            \n\u003e\u003e Timy (Half way) 0.557577 seconds\n\u003e\u003e Timy 0.988087 seconds            \n```\n\nAnother usage of tracking in a prime factors function\n\n```python\ndef prime_factors(n):\n    with timy.Timer('Factors') as timer:\n        i = 2\n        factors = []\n        def add_factor(n):\n            factors.append(n)\n            timer.track('Found a factor')\n\n        while i * i \u003c= n:\n            if n % i == 0:\n                add_factor(i)\n                n //= i\n            else:\n                i += 1\n        return factors + [n]\n\nfactors = prime_factors(600851475143)\nprint(factors)\n\n\u003e\u003e Factors (Found a factor) 0.000017 seconds\n\u003e\u003e Factors (Found a factor) 0.000376 seconds\n\u003e\u003e Factors (Found a factor) 0.001547 seconds\n\u003e\u003e Factors 0.001754 seconds\n\u003e\u003e [71, 839, 1471, 6857]\n```\n\n### Configuring\n\n#### Importing timy config\n\n```python\nfrom timy.settings import timy_config\n```\n\n#### Enable or disable timy trackings\nYou can enable or disable timy trackings with the `tracking` value.\n\u003e The default value of `tracking` is `True`\n\n```python\ntimy_config.tracking = False\n```\n\n#### Changing the way timy outputs information\nYou can choose between print or logging for all timy outputs by setting the\nvalue of `tracking_mode`.\n\u003e The default value of `tracking_mode` is `TrackingMode.PRINTING`.\n\n```python\nfrom timy.settings import (\n    timy_config,\n    TrackingMode\n)\n\ntimy_config.tracking_mode = TrackingMode.LOGGING\n```\n\ntimy logs at the INFO level, which is not printed or stored by default. To\nconfigure the logging system to print all INFO messages do\n```\nimport logging\nlogging.basicConfig(level=logging.INFO)\n```\nor to configure the logging system to print only timy's INFO messages do\n```\nimport logging\nlogging.basicConfig()\nlogging.getLogger('timy').level=logging.INFO\n```\n\n## Contribute\nContributions are **always** welcome, but keep it simple and small.\n\n## License\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Framonsaraiva%2Ftimy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Framonsaraiva%2Ftimy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Framonsaraiva%2Ftimy/lists"}