{"id":13468585,"url":"https://github.com/ionelmc/pytest-benchmark","last_synced_at":"2025-04-23T20:48:51.382Z","repository":{"id":21710261,"uuid":"25031755","full_name":"ionelmc/pytest-benchmark","owner":"ionelmc","description":"pytest fixture for benchmarking code","archived":false,"fork":false,"pushed_at":"2025-04-08T13:10:23.000Z","size":1762,"stargazers_count":1297,"open_issues_count":113,"forks_count":121,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-04-20T10:08:00.114Z","etag":null,"topics":["benchmark","benchmarking","performance","pytest","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ionelmc.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":"CONTRIBUTING.rst","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":"AUTHORS.rst","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-10-10T10:55:33.000Z","updated_at":"2025-04-09T12:53:56.000Z","dependencies_parsed_at":"2023-02-10T09:45:20.960Z","dependency_job_id":"6273226e-e3df-4258-90c4-d4d37ac64ac9","html_url":"https://github.com/ionelmc/pytest-benchmark","commit_stats":{"total_commits":1024,"total_committers":46,"mean_commits":22.26086956521739,"dds":0.1455078125,"last_synced_commit":"e1c4371f0988f9919bd15afdbadf4bd595adbc7a"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ionelmc%2Fpytest-benchmark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ionelmc%2Fpytest-benchmark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ionelmc%2Fpytest-benchmark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ionelmc%2Fpytest-benchmark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ionelmc","download_url":"https://codeload.github.com/ionelmc/pytest-benchmark/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250513713,"owners_count":21443204,"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":["benchmark","benchmarking","performance","pytest","python"],"created_at":"2024-07-31T15:01:14.176Z","updated_at":"2025-04-23T20:48:51.361Z","avatar_url":"https://github.com/ionelmc.png","language":"Python","funding_links":[],"categories":["Python","Testing Tools"],"sub_categories":[],"readme":"========\nOverview\n========\n\n.. start-badges\n\n.. list-table::\n    :stub-columns: 1\n\n    * - docs\n      - |docs| |gitter|\n    * - tests\n      - |github-actions| |coveralls| |codecov|\n    * - package\n      - |version| |wheel| |supported-versions| |supported-implementations| |commits-since|\n.. |docs| image:: https://readthedocs.org/projects/pytest-benchmark/badge/?style=flat\n    :target: https://readthedocs.org/projects/pytest-benchmark/\n    :alt: Documentation Status\n\n.. |github-actions| image:: https://github.com/ionelmc/pytest-benchmark/actions/workflows/github-actions.yml/badge.svg\n    :alt: GitHub Actions Build Status\n    :target: https://github.com/ionelmc/pytest-benchmark/actions\n.. |gitter| image:: https://badges.gitter.im/ionelmc/pytest-benchmark.svg\n    :alt: Join the chat at https://gitter.im/ionelmc/pytest-benchmark\n    :target: https://gitter.im/ionelmc/pytest-benchmark\n\n.. |coveralls| image:: https://coveralls.io/repos/github/ionelmc/pytest-benchmark/badge.svg?branch=main\n    :alt: Coverage Status\n    :target: https://coveralls.io/github/ionelmc/pytest-benchmark?branch=main\n\n.. |codecov| image:: https://codecov.io/gh/ionelmc/pytest-benchmark/branch/main/graphs/badge.svg?branch=main\n    :alt: Coverage Status\n    :target: https://app.codecov.io/github/ionelmc/pytest-benchmark\n\n.. |version| image:: https://img.shields.io/pypi/v/pytest-benchmark.svg\n    :alt: PyPI Package latest release\n    :target: https://pypi.org/project/pytest-benchmark\n\n.. |wheel| image:: https://img.shields.io/pypi/wheel/pytest-benchmark.svg\n    :alt: PyPI Wheel\n    :target: https://pypi.org/project/pytest-benchmark\n\n.. |supported-versions| image:: https://img.shields.io/pypi/pyversions/pytest-benchmark.svg\n    :alt: Supported versions\n    :target: https://pypi.org/project/pytest-benchmark\n\n.. |supported-implementations| image:: https://img.shields.io/pypi/implementation/pytest-benchmark.svg\n    :alt: Supported implementations\n    :target: https://pypi.org/project/pytest-benchmark\n\n.. |commits-since| image:: https://img.shields.io/github/commits-since/ionelmc/pytest-benchmark/v5.1.0.svg\n    :alt: Commits since latest release\n    :target: https://github.com/ionelmc/pytest-benchmark/compare/v5.1.0...main\n\n\n\n.. end-badges\n\nA ``pytest`` fixture for benchmarking code. It will group the tests into rounds that are calibrated to the chosen\ntimer.\n\nSee calibration_ and FAQ_.\n\n* Free software: BSD 2-Clause License\n\nInstallation\n============\n\n::\n\n    pip install pytest-benchmark\n\nDocumentation\n=============\n\nFor latest release: `pytest-benchmark.readthedocs.org/en/stable \u003chttp://pytest-benchmark.readthedocs.org/en/stable/\u003e`_.\n\nFor master branch (may include documentation fixes): `pytest-benchmark.readthedocs.io/en/latest \u003chttp://pytest-benchmark.readthedocs.io/en/latest/\u003e`_.\n\nExamples\n========\n\nBut first, a prologue:\n\n    This plugin tightly integrates into pytest. To use this effectively you should know a thing or two about pytest first.\n    Take a look at the `introductory material \u003chttp://docs.pytest.org/en/latest/getting-started.html\u003e`_\n    or watch `talks \u003chttp://docs.pytest.org/en/latest/talks.html\u003e`_.\n\n    Few notes:\n\n    * This plugin benchmarks functions and only that. If you want to measure block of code\n      or whole programs you will need to write a wrapper function.\n    * In a test you can only benchmark one function. If you want to benchmark many functions write more tests or\n      use `parametrization \u003chttp://docs.pytest.org/en/latest/parametrize.html\u003e`_.\n    * To run the benchmarks you simply use `pytest` to run your \"tests\". The plugin will automatically do the\n      benchmarking and generate a result table. Run ``pytest --help`` for more details.\n\nThis plugin provides a `benchmark` fixture. This fixture is a callable object that will benchmark any function passed\nto it.\n\nExample:\n\n.. code-block:: python\n\n    def something(duration=0.000001):\n        \"\"\"\n        Function that needs some serious benchmarking.\n        \"\"\"\n        time.sleep(duration)\n        # You may return anything you want, like the result of a computation\n        return 123\n\n    def test_my_stuff(benchmark):\n        # benchmark something\n        result = benchmark(something)\n\n        # Extra code, to verify that the run completed correctly.\n        # Sometimes you may want to check the result, fast functions\n        # are no good if they return incorrect results :-)\n        assert result == 123\n\nYou can also pass extra arguments:\n\n.. code-block:: python\n\n    def test_my_stuff(benchmark):\n        benchmark(time.sleep, 0.02)\n\nOr even keyword arguments:\n\n.. code-block:: python\n\n    def test_my_stuff(benchmark):\n        benchmark(time.sleep, duration=0.02)\n\nAnother pattern seen in the wild, that is not recommended for micro-benchmarks (very fast code) but may be convenient:\n\n.. code-block:: python\n\n    def test_my_stuff(benchmark):\n        @benchmark\n        def something():  # unnecessary function call\n            time.sleep(0.000001)\n\nA better way is to just benchmark the final function:\n\n.. code-block:: python\n\n    def test_my_stuff(benchmark):\n        benchmark(time.sleep, 0.000001)  # way more accurate results!\n\nIf you need to do fine control over how the benchmark is run (like a `setup` function, exact control of `iterations` and\n`rounds`) there's a special mode - pedantic_:\n\n.. code-block:: python\n\n    def my_special_setup():\n        ...\n\n    def test_with_setup(benchmark):\n        benchmark.pedantic(something, setup=my_special_setup, args=(1, 2, 3), kwargs={'foo': 'bar'}, iterations=10, rounds=100)\n\nScreenshots\n-----------\n\nNormal run:\n\n.. image:: https://github.com/ionelmc/pytest-benchmark/raw/master/docs/screenshot.png\n    :alt: Screenshot of pytest summary\n\nCompare mode (``--benchmark-compare``):\n\n.. image:: https://github.com/ionelmc/pytest-benchmark/raw/master/docs/screenshot-compare.png\n    :alt: Screenshot of pytest summary in compare mode\n\nHistogram (``--benchmark-histogram``):\n\n.. image:: https://cdn.rawgit.com/ionelmc/pytest-benchmark/94860cc8f47aed7ba4f9c7e1380c2195342613f6/docs/sample-tests_test_normal.py_test_xfast_parametrized%5B0%5D.svg\n    :alt: Histogram sample\n\n..\n\n    Also, it has `nice tooltips \u003chttps://cdn.rawgit.com/ionelmc/pytest-benchmark/master/docs/sample.svg\u003e`_.\n\nDevelopment\n===========\n\nTo run the all tests run::\n\n    tox\n\nCredits\n=======\n\n* Timing code and ideas taken from: https://github.com/vstinner/misc/blob/34d3128468e450dad15b6581af96a790f8bd58ce/python/benchmark.py\n\n.. _FAQ: http://pytest-benchmark.readthedocs.org/en/latest/faq.html\n.. _calibration: http://pytest-benchmark.readthedocs.org/en/latest/calibration.html\n.. _pedantic: http://pytest-benchmark.readthedocs.org/en/latest/pedantic.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fionelmc%2Fpytest-benchmark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fionelmc%2Fpytest-benchmark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fionelmc%2Fpytest-benchmark/lists"}