Update README.md #28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # bigocheck Complexity Analysis Workflow | |
| # Author: gadwant | |
| # | |
| # This workflow runs complexity analysis on your codebase | |
| # and detects regressions in time/space complexity. | |
| # | |
| # Usage: | |
| # 1. Copy this file to .github/workflows/complexity.yml | |
| # 2. Configure target functions in the matrix | |
| # 3. Optionally save baselines for regression detection | |
| name: Complexity Analysis | |
| on: | |
| push: | |
| branches: [main, master] | |
| pull_request: | |
| branches: [main, master] | |
| jobs: | |
| complexity-check: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ['3.11'] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install bigocheck | |
| # Install your project | |
| pip install -e . | |
| - name: Run complexity analysis | |
| run: | | |
| # Example: Analyze your functions | |
| # bigocheck run --target mymodule:myfunc --sizes 100 500 1000 --json > results.json | |
| echo "Add your complexity checks here" | |
| # Optional: Regression detection against baseline | |
| # - name: Check for regressions | |
| # run: | | |
| # python -c " | |
| # from bigocheck import benchmark_function, load_baseline, detect_regression | |
| # from mymodule import my_function | |
| # | |
| # current = benchmark_function(my_function, sizes=[100, 500, 1000]) | |
| # baseline = load_baseline('baselines/my_function.json') | |
| # result = detect_regression(current, baseline, time_threshold=0.2) | |
| # | |
| # if result.has_regression: | |
| # print('❌ REGRESSION DETECTED') | |
| # print(result.message) | |
| # exit(1) | |
| # print('✅ No regressions detected') | |
| # " | |
| # Optional: Save baseline on main branch | |
| # save-baseline: | |
| # runs-on: ubuntu-latest | |
| # if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| # | |
| # steps: | |
| # - uses: actions/checkout@v4 | |
| # | |
| # - name: Set up Python | |
| # uses: actions/setup-python@v5 | |
| # with: | |
| # python-version: '3.11' | |
| # | |
| # - name: Install and save baseline | |
| # run: | | |
| # pip install bigocheck -e . | |
| # python -c " | |
| # from bigocheck import benchmark_function, save_baseline | |
| # from mymodule import my_function | |
| # | |
| # analysis = benchmark_function(my_function, sizes=[100, 500, 1000], memory=True) | |
| # save_baseline(analysis, 'baselines/my_function.json', name='${{ github.sha }}') | |
| # " | |
| # | |
| # - name: Commit baseline | |
| # uses: stefanzweifel/git-auto-commit-action@v5 | |
| # with: | |
| # commit_message: "Update complexity baseline" | |
| # file_pattern: "baselines/*.json" |