{"id":18403710,"url":"https://github.com/russellluo/pyprof-timer","last_synced_at":"2025-04-07T07:32:46.324Z","repository":{"id":62582740,"uuid":"103423460","full_name":"RussellLuo/pyprof-timer","owner":"RussellLuo","description":"A timer for profiling a Python function or snippet.","archived":false,"fork":false,"pushed_at":"2019-06-23T11:48:59.000Z","size":29,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-22T14:41:29.992Z","etag":null,"topics":["profiling","python","timer"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RussellLuo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-13T16:26:59.000Z","updated_at":"2021-07-31T01:38:05.000Z","dependencies_parsed_at":"2022-11-03T20:18:08.383Z","dependency_job_id":null,"html_url":"https://github.com/RussellLuo/pyprof-timer","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/RussellLuo%2Fpyprof-timer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RussellLuo%2Fpyprof-timer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RussellLuo%2Fpyprof-timer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RussellLuo%2Fpyprof-timer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RussellLuo","download_url":"https://codeload.github.com/RussellLuo/pyprof-timer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247612510,"owners_count":20966768,"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":["profiling","python","timer"],"created_at":"2024-11-06T02:47:59.425Z","updated_at":"2025-04-07T07:32:43.945Z","avatar_url":"https://github.com/RussellLuo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pyprof-timer\n\nA timer for profiling a Python function or snippet.\n\n\n## Installation\n\nRelease version:\n\n```bash\n$ pip install pyprof-timer\n```\n\nDevelopment version:\n\n```bash\n$ pip install -e git+https://github.com/RussellLuo/pyprof-timer.git#egg=pyprof-timer\n```\n\n\n## Quick start\n\n### Manual profiling\n\nSometimes, we only want to measure the execution time of partial snippets or a few functions, then we can inject all timing points into our code manually by leveraging `Timer`:\n\n```python\n\n# manual_example.py\n\nimport time\n\nfrom pyprof_timer import Timer, Tree\n\n\ndef main():\n    t = Timer('sleep1', parent_name='main').start()\n    time.sleep(1)\n    t.stop()\n\n    t = Timer('sleep2', parent_name='main').start()\n    time.sleep(1.5)\n    t.stop()\n\n    print(Tree(Timer.root))\n\n\nif __name__ == '__main__':\n    main()\n```\n\nRun the example code:\n\n```bash\n$ python manual_example.py\n```\n\nand it will show you the profiling result:\n\n```\n2.503s  main\n├── 1.001s  sleep1\n└── 1.501s  sleep2\n\n```\n\n### Automatic profiling\n\nMore commonly, chances are that we want to measure the execution time of an entry function and all its subfunctions. In this case, it's too tedious to do it manually, and we can leverage `Profiler` to inject all the timing points for us automatically:\n\n```python\n\n# automatic_example.py\n\nimport time # line number 1\n\nfrom pyprof_timer import Profiler, Tree\n\n\ndef f1():\n    time.sleep(1)\n\n\ndef f2():\n    time.sleep(1.5)\n\n\ndef show(p):\n    print(Tree(p.root))\n\n\n@Profiler(depth=2, on_disable=show)\ndef main():\n    f1()\n    f2()\n\n\nif __name__ == '__main__':\n    main()\n```\n\nRun the example code:\n\n```bash\n$ python automatic_example.py\n```\n\nand it will show you the profiling result:\n\n```\n2.506s  main  [automatic_example.py:18]\n├── 1.001s  f1  [automatic_example.py:6]\n│   └── 1.001s  \u003ctime.sleep\u003e\n└── 1.505s  f2  [automatic_example.py:10]\n    └── 1.505s  \u003ctime.sleep\u003e\n\n```\n\n**NOTE**: If the parameter `depth` is missing, the **profiling output** will be **overwhelming** and the **runtime overhead** will be **high**.\n\n\n## Supported frameworks\n\nWhile you can do profiling on normal Python code, as a web developer, chances are that you will usually do profiling on web service code.\n\nCurrently supported web frameworks:\n\n- [Flask](http://flask.pocoo.org/)\n\n\n## Examples\n\nFor profiling web service code (involving web requests), check out [examples](examples).\n\n\n## License\n\n[MIT](http://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frussellluo%2Fpyprof-timer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frussellluo%2Fpyprof-timer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frussellluo%2Fpyprof-timer/lists"}