Giter Club home page Giter Club logo

pytest-benchmark-commenter's Introduction

Comment with PyTest Benchmark Github Action

This GitHub action comments on a pull request with the benchmark results written out from a pytest-benchmark run.

Usage

Create (or update) a workflow file in .github/workflow/benchmark.yml and add this action after you run your benchmark tests. You might need to tweak the installation and test run below to your own needs.

name: Benchmark
on: [pull_request]

jobs:
  benchmark:
    name: Run pytest-benchmark
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v1
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
      - name: Run benchmark
        run: |
          pytest benchmark.py --benchmark-only --benchmark-json output.json
      - name: Publish results
        uses: nils-braun/pytest-benchmark-commenter@v2

The github action is only supported for pull request events.

Configuration

Name Default Description
github-token ${{ secrets.GITHUB_TOKEN }} Change this, if you do not want to use the default token
benchmark-file output.json Where your benchmark file is stored
comparison-benchmark-file empty Where to find the json output of an old pytest-benchmark, for comparison. Empty for no comparison.

Usage for comparison

If you want to compare the results of the benchmarks now to the most recent run on your default branch, you could do the following:

Create a workflow to upload the benchmarks on your default branch, e.g. upload.yml:

name: Upload the artifact
on:
  push:
    branches:
      - <your default branch>

jobs:
  test_action_job:
    runs-on: ubuntu-latest
    name: Test out the action in this repository
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      ... do the benchmarking ...

      - name: Upload the file
        uses: actions/upload-artifact@v2
        with:
          name: benchmark_results
          path: output.json

Now you can reference this in your workflow for comparison:

name: Test Action
on:
  pull_request:
    branches:
      - master

jobs:
  test_action_job:
    runs-on: ubuntu-latest
    name: Test out the action in this repository
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      ... do the benchmarking ...

      - name: Download artifact
        uses: dawidd6/action-download-artifact@v2
        with:
          github_token: ${{ github.token }}
          workflow: upload.yml
          name: benchmark_results
          path: old_benchmark
          commit: ${{github.event.pull_request.base.sha}}
        continue-on-error: true
      - name: Run the action
        uses: nils-braun/pytest-benchmark-commenter@v2
        with:
          comparison-benchmark-file: "old_benchmark/output.json"

pytest-benchmark-commenter's People

Contributors

dependabot[bot] avatar nils-braun avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

pytest-benchmark-commenter's Issues

Optional different formatting for output table for microtesting

Just want to start by saying thanks for creating this, it's a great addition to the github actions market.

Just deployed it to test our new library, but the library is a log parser where the tests are doing tight loops on the parsing methods, so the attributes we care most about are: operations per second, rounds taken and mean. However the mean times are in microseconds, so round down to 0.00 on the current table.

Not sure if you'd be interested in a fully configurable way to decide on units, and which columns to include, or just have a templated format option between normal testing and this sort of testing.

----------------------------------------------------------------------------------------------------- benchmark: 8 tests -----------------------------------------------------------------------------------------------------
Name (time in us)                                     Min                   Max                Mean              StdDev              Median                IQR            Outliers  OPS (Kops/s)            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_apache_access_speed                          19.3000 (1.0)        370.1000 (1.93)      21.7065 (1.0)        6.0220 (1.0)       20.3000 (1.0)       0.7000 (1.00)    1432;2866       46.0692 (1.0)       21979           1
test_cloudflare_access_speed                      48.8000 (2.53)       352.4000 (1.84)      54.0498 (2.49)      14.2508 (2.37)      50.6000 (2.49)      1.5000 (2.14)     536;1256       18.5014 (0.40)       8937           1
test_apache_access_speed_validation              102.7000 (5.32)       191.6000 (1.0)      107.8831 (4.97)      10.5300 (1.75)     105.0000 (5.17)      1.4500 (2.07)        10;22        9.2693 (0.20)        148           1
test_cloudflare_access_speed_with_validation     145.4000 (7.53)     3,078.3000 (16.07)    292.0481 (13.45)    265.1503 (44.03)    240.7500 (11.86)    56.1000 (80.14)        7;20        3.4241 (0.07)        158           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.