{"id":27171430,"url":"https://github.com/codspeedhq/pytest-codspeed","last_synced_at":"2025-05-16T18:09:20.631Z","repository":{"id":62745493,"uuid":"535377158","full_name":"CodSpeedHQ/pytest-codspeed","owner":"CodSpeedHQ","description":"Pytest plugin to create CodSpeed benchmarks","archived":false,"fork":false,"pushed_at":"2025-05-14T15:48:05.000Z","size":280,"stargazers_count":79,"open_issues_count":14,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-14T15:54:04.611Z","etag":null,"topics":["benchmarking","codspeed","pytest","python"],"latest_commit_sha":null,"homepage":"https://codspeed.io","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/CodSpeedHQ.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-09-11T17:41:50.000Z","updated_at":"2025-05-13T05:51:57.000Z","dependencies_parsed_at":"2023-11-14T14:29:13.793Z","dependency_job_id":"9196fb24-24f1-4617-bd76-557d416ef8d1","html_url":"https://github.com/CodSpeedHQ/pytest-codspeed","commit_stats":{"total_commits":79,"total_committers":3,"mean_commits":"26.333333333333332","dds":"0.025316455696202556","last_synced_commit":"367ef470149485a8267e491f14a6c413d2821b03"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodSpeedHQ%2Fpytest-codspeed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodSpeedHQ%2Fpytest-codspeed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodSpeedHQ%2Fpytest-codspeed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodSpeedHQ%2Fpytest-codspeed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodSpeedHQ","download_url":"https://codeload.github.com/CodSpeedHQ/pytest-codspeed/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254582907,"owners_count":22095518,"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":["benchmarking","codspeed","pytest","python"],"created_at":"2025-04-09T08:34:25.741Z","updated_at":"2025-05-16T18:09:20.595Z","avatar_url":"https://github.com/CodSpeedHQ.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003ch1\u003epytest-codspeed\u003c/h1\u003e\n\n[![CI](https://github.com/CodSpeedHQ/pytest-codspeed/actions/workflows/ci.yml/badge.svg)](https://github.com/CodSpeedHQ/pytest-codspeed/actions/workflows/ci.yml)\n[![PyPi Version](https://img.shields.io/pypi/v/pytest-codspeed?color=%2334D058\u0026label=pypi)](https://pypi.org/project/pytest-codspeed)\n![Python Version](https://img.shields.io/badge/python-3.9%20|%203.10%20|%203.11%20|%203.12%20|%203.13-informational.svg)\n[![Discord](https://img.shields.io/badge/chat%20on-discord-7289da.svg)](https://discord.com/invite/MxpaCfKSqF)\n[![CodSpeed Badge](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/CodSpeedHQ/pytest-codspeed)\n\nPytest plugin to create CodSpeed benchmarks\n\n\u003c/div\u003e\n\n## Requirements\n\n**Python**: 3.9 and later\n\n**pytest**: any recent version\n\n## Installation\n\n```shell\npip install pytest-codspeed\n```\n\n## Usage\n\n### Creating benchmarks\n\nCreating benchmarks with `pytest-codspeed` is compatible with the standard `pytest-benchmark` API. So if you already have benchmarks written with it, you can start using `pytest-codspeed` right away.\n\n#### Marking a whole test function as a benchmark with `pytest.mark.benchmark`\n\n```python\nimport pytest\nfrom statistics import median\n\n@pytest.mark.benchmark\ndef test_median_performance():\n    return median([1, 2, 3, 4, 5])\n```\n\n#### Benchmarking selected lines of a test function with the `benchmark` fixture\n\n```python\nimport pytest\nfrom statistics import mean\n\ndef test_mean_performance(benchmark):\n    # Precompute some data useful for the benchmark but that should not be\n    # included in the benchmark time\n    data = [1, 2, 3, 4, 5]\n\n    # Benchmark the execution of the function\n    benchmark(lambda: mean(data))\n\n\ndef test_mean_and_median_performance(benchmark):\n    # Precompute some data useful for the benchmark but that should not be\n    # included in the benchmark time\n    data = [1, 2, 3, 4, 5]\n\n    # Benchmark the execution of the function:\n    # The `@benchmark` decorator will automatically call the function and\n    # measure its execution\n    @benchmark\n    def bench():\n        mean(data)\n        median(data)\n```\n\n### Running benchmarks\n\n#### Testing the benchmarks locally\n\nIf you want to run only the benchmarks tests locally, you can use the `--codspeed` pytest flag:\n\n```shell\npytest tests/ --codspeed\n```\n\n\u003e **Note:** Running `pytest-codspeed` locally will not produce any performance reporting. It's only useful for making sure that your benchmarks are working as expected. If you want to get performance reporting, you should run the benchmarks in your CI.\n\n#### In your CI\n\nYou can use the [CodSpeedHQ/action](https://github.com/CodSpeedHQ/action) to run the benchmarks in Github Actions and upload the results to CodSpeed.\n\nExample workflow:\n\n```yaml\nname: CodSpeed\n\non:\n  push:\n    branches:\n      - \"main\" # or \"master\"\n  pull_request:\n\njobs:\n  benchmarks:\n    name: Run benchmarks\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n      - uses: actions/setup-python@v5\n        with:\n          python-version: \"3.12\"\n      - name: Install dependencies\n        run: pip install -r requirements.txt\n      - name: Run benchmarks\n        uses: CodSpeedHQ/action@v3\n        with:\n          token: ${{ secrets.CODSPEED_TOKEN }}\n          run: pytest tests/ --codspeed\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodspeedhq%2Fpytest-codspeed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodspeedhq%2Fpytest-codspeed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodspeedhq%2Fpytest-codspeed/lists"}