Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .github/workflows/benchmark.yml

This file was deleted.

7 changes: 4 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ repos:
- id: check-toml
- id: requirements-txt-fixer
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.11
rev: v0.13.1
hooks:
- id: ruff
args: [--fix]
# Run the linter.
- id: ruff-check
# Run the formatter.
- id: ruff-format
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Test](https://github.com/cpp-linter/cpp-linter-hooks/actions/workflows/test.yml/badge.svg)](https://github.com/cpp-linter/cpp-linter-hooks/actions/workflows/test.yml)
[![CodeQL](https://github.com/cpp-linter/cpp-linter-hooks/actions/workflows/codeql.yml/badge.svg)](https://github.com/cpp-linter/cpp-linter-hooks/actions/workflows/codeql.yml)

A powerful [pre-commit](https://pre-commit.com/) hook for auto-formatting and linting C/C++ code with `clang-format` and `clang-tidy`.
A pre-commit hook that automatically formats and lints your C/C++ code using `clang-format` and `clang-tidy`.

## Table of Contents

Expand Down
4 changes: 1 addition & 3 deletions testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ pre-commit try-repo ./.. clang-tidy --verbose --all-files

## Benchmark

```bash
python3 testing/benchmark_hooks.py
```
See [benchmark](./benchmark.md).
67 changes: 57 additions & 10 deletions testing/benchmark.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,69 @@ This document outlines the benchmarking process for comparing the performance of

> About tests performance can be found at: [![CodSpeed Badge](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/cpp-linter/cpp-linter-hooks)

## Running the Benchmark
## Run benchmark separately

```bash
python3 testing/benchmark_hooks.py
rm -rf examples || true
git clone --depth 1 --quiet https://github.com/gouravthakur39/beginners-C-program-examples.git examples

pre-commit clean
hyperfine --warmup 1 -r 10 'pre-commit run --config testing/test-cpp-linter-hooks.yaml --all-files'

rm -rf examples || true
git clone --depth 1 --quiet https://github.com/gouravthakur39/beginners-C-program-examples.git examples
pre-commit clean

hyperfine --warmup 1 -r 10 'pre-commit run --config testing/test-mirrors-clang-format.yaml --all-files'
```

Results:

```bash
# Updated on 2025-09-19

Cleaned /home/sxp/.cache/pre-commit.
Benchmark 1: pre-commit run --config testing/test-cpp-linter-hooks.yaml --all-files
Time (mean ± σ): 150.2 ms ± 1.8 ms [User: 121.7 ms, System: 29.2 ms]
Range (min … max): 148.3 ms … 153.9 ms 10 runs

Cleaned /home/sxp/.cache/pre-commit.
Benchmark 1: pre-commit run --config testing/test-mirrors-clang-format.yaml --all-files
Time (mean ± σ): 122.6 ms ± 1.9 ms [User: 98.0 ms, System: 24.7 ms]
Range (min … max): 120.3 ms … 125.5 ms 10 runs
```

## Results
### Run benchmark comparison

Compare the results of both commands.

```bash
# Updated on 2025-09-02
Benchmark Results:
rm -rf examples || true
git clone --depth 1 --quiet https://github.com/gouravthakur39/beginners-C-program-examples.git examples

hyperfine -i --warmup 1 -r 20 'pre-commit run --config ../testing/test-cpp-linter-hooks.yaml --all-files' 'pre-commit run --config ../testing/test-mirrors-clang-format.yaml --all-files'
```

Hook | Avg (s) | Std (s) | Min (s) | Max (s) | Runs
---------------------+------------------+------------------+------------------+------------------+-----------------
cpp-linter-hooks | 12.473 | 1.738 | 11.334 | 15.514 | 5
mirrors-clang-format | 4.960 | 0.229 | 4.645 | 5.284 | 5
Results:

```bash
# Updated on 2025-09-19
Benchmark 1: pre-commit run --config ../testing/test-cpp-linter-hooks.yaml --all-files
Time (mean ± σ): 84.1 ms ± 3.2 ms [User: 73.5 ms, System: 10.2 ms]
Range (min … max): 79.7 ms … 95.2 ms 20 runs

Results saved to testing/benchmark_results.txt
Warning: Ignoring non-zero exit code.

Benchmark 2: pre-commit run --config ../testing/test-mirrors-clang-format.yaml --all-files
Time (mean ± σ): 85.0 ms ± 3.0 ms [User: 71.8 ms, System: 13.3 ms]
Range (min … max): 81.0 ms … 91.0 ms 20 runs

Warning: Ignoring non-zero exit code.

Summary
'pre-commit run --config ../testing/test-cpp-linter-hooks.yaml --all-files' ran
1.01 ± 0.05 times faster than 'pre-commit run --config ../testing/test-mirrors-clang-format.yaml --all-files'
```

> [!NOTE]
> The results may vary based on the system and environment where the benchmarks are run.
6 changes: 0 additions & 6 deletions testing/benchmark_hook_1.yaml

This file was deleted.

145 changes: 0 additions & 145 deletions testing/benchmark_hooks.py

This file was deleted.

6 changes: 0 additions & 6 deletions testing/benchmark_results.txt

This file was deleted.

6 changes: 6 additions & 0 deletions testing/test-cpp-linter-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/cpp-linter/cpp-linter-hooks
rev: v1.1.3
hooks:
- id: clang-format # v 21.1.0
args: [--style=file]
File renamed without changes.
Loading