{"id":19855184,"url":"https://github.com/leggedrobotics/pytictac","last_synced_at":"2025-05-02T01:30:44.595Z","repository":{"id":228612525,"uuid":"612558149","full_name":"leggedrobotics/pytictac","owner":"leggedrobotics","description":"Simple Timing Utils","archived":false,"fork":false,"pushed_at":"2023-03-27T09:26:31.000Z","size":12,"stargazers_count":12,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-06T20:46:32.741Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/leggedrobotics.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-03-11T10:02:58.000Z","updated_at":"2024-11-30T15:36:34.000Z","dependencies_parsed_at":"2024-03-19T17:21:12.334Z","dependency_job_id":"c7032deb-1b4d-40a7-ae57-b2439148cc88","html_url":"https://github.com/leggedrobotics/pytictac","commit_stats":null,"previous_names":["leggedrobotics/pytictac"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leggedrobotics%2Fpytictac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leggedrobotics%2Fpytictac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leggedrobotics%2Fpytictac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leggedrobotics%2Fpytictac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leggedrobotics","download_url":"https://codeload.github.com/leggedrobotics/pytictac/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251969274,"owners_count":21673183,"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":[],"created_at":"2024-11-12T14:11:58.887Z","updated_at":"2025-05-02T01:30:42.134Z","avatar_url":"https://github.com/leggedrobotics.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TicTac - Time your Torch Code Easily\nThis repository simplifies timing of code by reducing the amount of boilerplate code needed. \nSpecifically, it provides a context manager that can be used to time a block of code. \nThe context manager will print the time taken to execute the block of code. \nAdditionally, full classes/objects can be timed easily and statistics are generated.\n\n\n# Installation\n```\npip3 install pytictac\n```\n\n\n# Basic Usage\n\nOld:\n```python\nimport torch\n\ndef func(x):\n    return x*2\n\nstart = torch.cuda.Event(enable_timing=True)\nend = torch.cuda.Event(enable_timing=True)\nstart.record()\n\n# Compute\nfunc(2)\n\nend.record()\ntorch.cuda.synchronize()\nprint(start.elapsed_time(end))\n```\n\nNew:\n```python\nfrom pytictac import Timer, CpuTimer\n\ndef func(x):\n    return x*2\n\n# Compute\nwith Timer(\"func2\"):\n    func(2)\n\nwith CpuTimer(\"func2\"):\n    func(2)\n```\nTerminal Output:\n```shell\nTime func2:  0.0655359998345375 ms\n```\n\nThere exists always a cpu version (using import time; st = time.time()) and a gpu-version (using torch events). \nThis is handy when you want to time for example a dataloader where you cannot use torch events.\n\n# Advanced Usage\n\n```python\nfrom pytictac import ClassTimer, ClassContextTimer, accumulate_time\n\n\nclass SmallObject:\n    def __init__(self):\n        self.x = 3\n\n    @accumulate_time\n    def method_a(self):\n        self.x += 2\n\n\nclass TestObject:\n    def __init__(self):\n        self.x = 3\n        self.small_obj = SmallObject()\n\n        self.cct = ClassTimer(objects=[self, self.small_obj], names=[\"Test Object\", \"Small Object\"], enabled=True)\n\n    @accumulate_time\n    def method_a(self):\n        self.x += 2\n        self.small_obj.method_a()\n\n    @accumulate_time\n    def method_b(self):\n        self.x += 2\n        with ClassContextTimer(parent_obj=self, block_name=\"method_b.1\", parent_method_name=\"method_b\"):\n            self.x = 3\n            with ClassContextTimer(\n                parent_obj=self, block_name=\"method_b.1.a\", parent_method_name=\"method_b.1\", n_level=2, cpu=True\n            ):\n                self.x = 4\n\n    @cpu_accumulate_time\n    def method_c(self):\n        self.x -= 2\n\n    @cpu_accumulate_time\n    def method_d(self):\n        self.x = 0\n\n    def __str__(self):\n        return self.cct.__str__()\n\n\nto = TestObject()\nto.method_a()\nto.method_a()\nto.method_a()\nto.method_b()\nto.method_c()\nprint(to)\n```\nTerminal Output:\n```shell\nTest Object                           total [ms]    count [n]        std [ms]       mean [ms]\n  +-  method_a:                       0.16          3                0.045          0.054           \n  +-  method_b:                       0.05          1                0.0            0.05            \n  +------  method_b.1:                0.03          1                0.0            0.027           \n  +-----------  method_b.1.a:         0.01          1                0.0            0.007           \n  +-  method_c:                       0.01          1                0.0            0.005           \nSmall Object                          total [ms]    count [n]        std [ms]       mean [ms]\n  +-  method_a:                       0.02          3                0.001          0.005       \n```\n\n# Releasing\n```\npython3 setup.py bdist_wheel \ntwine upload dist/* \n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleggedrobotics%2Fpytictac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleggedrobotics%2Fpytictac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleggedrobotics%2Fpytictac/lists"}