{"id":20590008,"url":"https://github.com/doist/timethat","last_synced_at":"2026-05-26T13:42:04.329Z","repository":{"id":12607379,"uuid":"15278393","full_name":"Doist/timethat","owner":"Doist","description":"timeit on steroids, a module for benchmarking","archived":false,"fork":false,"pushed_at":"2023-12-15T14:50:42.000Z","size":5,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-06T13:39:13.581Z","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":"kungfoo/geohash-java","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Doist.png","metadata":{"files":{"readme":"README.rst","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-12-18T09:00:12.000Z","updated_at":"2024-11-28T16:28:28.000Z","dependencies_parsed_at":"2024-11-16T07:33:39.588Z","dependency_job_id":"ee49e772-ed45-4f84-8184-d46c098c1da5","html_url":"https://github.com/Doist/timethat","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Doist/timethat","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Doist%2Ftimethat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Doist%2Ftimethat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Doist%2Ftimethat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Doist%2Ftimethat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Doist","download_url":"https://codeload.github.com/Doist/timethat/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Doist%2Ftimethat/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33523658,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T03:12:49.672Z","status":"ssl_error","status_checked_at":"2026-05-26T03:12:47.976Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-16T07:33:36.036Z","updated_at":"2026-05-26T13:42:04.313Z","avatar_url":"https://github.com/Doist.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n**timethat** -- timeit on steroids, a module for benchmarking.\n\nDependency: numpy\n\nTimethat helps you to define you own setups and teardowns without creating\nseparate functions for that. The drawback is that you have to define the\ntesting cycle explicitly by yourself\n\nExample\n----------\n\nA simple and pretty much useless example, where we want to test the speed of\nreading data from JSON file\n\n.. code-block:: python\n\n    import timethat as tt\n    import os\n    import json\n\n    for benchmark in tt.repeat(1000, name='my benchmark'):\n        # setup actions\n        data = {'key': 'value'}\n        with open('test.json', 'w') as fd:\n            json.dump(data, fd)\n        # the test itself\n        with benchmark:  # that's how we mark that we are in the benchmark\n            with open('test.json') as fd:\n                data = json.load(fd)\n        # teardown actions\n        os.unlink('test.json')\n\n\nThen you may call ``benchmark.summary``, and get the summary of the results.\nMean execution time, as well as the range which 95% of results fit in.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e print benchmark.summary()\n    my benchmark                       37.61 msec     95% range [28.85 msec, 101.09 msec]\n\nAlthough it's somewhat uncommon, the ``benchmark`` variable is the same\nin all cycles of the loop. If you feel uncomfortable with it, you may create\nthe object explicitly\n\n.. code-block:: python\n\n    benchmark = tt.Benchmark(name='my benchmark')\n    for i in xrange(1000):\n        ...\n        # here the same code goes\n\n\nWorking with counters\n-------------------------\n\nAs you optimize your code, you may be interested in getting some extra metrics\nalong the way: how many times a database calls were made, same for specific\nfunction calls, cache hits / misses, etc.\n\nThere is a special counter function to help you with that. All you need is to\ncall it when you want to count a resource or operation:\n\n.. code-block:: python\n\n    ...\n    tt.incr('get_user_cache_miss')\n    ...\n    tt.incr('mysql_select')\n\nThe counter will be incremented only if it's been executed within a benchmark\ncontext.\n\nHint: you won't probably be able to patch your library / framework just to\ninsert a bunch of :func:`incr` calls there. Instead, if your framework can\ndo it, you may add a special in-benchmark signal handler calling `tt.incr(...)`\nwhenever you need.\n\nTo work with results, here are a number of counter-specific methods. Basic\nfunctions are:\n\n- :func:`Benchmark.counters()` -- get the set of all benchmark counters\n  (as the set of strings)\n- :func:`Benchmark.counter_values(counter_name)` -- get values of the the\n  specific counter, one per test\n\nAdditionally, there are functions :func:`counter_percentile`,\n:func:`counter_percentile_str`, :func:`counter_mean` and\n:func:`counter_mean_str` to get results in a more convenient way.\n\nThe :func:`summary` method takes counters into account and returns the result\nwith time and all counters statistics, if any.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoist%2Ftimethat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoist%2Ftimethat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoist%2Ftimethat/lists"}