Skip to content

Commit 4819ce9

Browse files
committed
feat: improve readme
1 parent 967871a commit 4819ce9

3 files changed

Lines changed: 175 additions & 27 deletions

File tree

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
testdata/perf_map/* filter=lfs diff=lfs merge=lfs -text
22
*.snap filter=lfs diff=lfs merge=lfs -text
3+
*.gif binary filter=lfs diff=lfs merge=lfs -text

README.md

Lines changed: 171 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
</picture>
77
</p>
88

9-
<h3 align="center">The toolkit to optimize code and avoid performance regressions.</h3>
9+
<h3 align="center">Optimize code performance and catch regressions early.</h3>
10+
1011
<p align="center"><a href="https://codspeed.io/login?flow=get-started&utm_source=github-readme">Get Started</a> · <a href="https://codspeed.io/docs?utm_source=github-readme">Documentation</a></p>
1112

1213
<br/>
@@ -20,7 +21,7 @@
2021
<a href="https://codspeed.io/?utm_source=badge"><img src="https://img.shields.io/endpoint?url=https://codspeed.io/badge.json" alt="CodSpeed Badge"></a>
2122
</p>
2223

23-
[![Video Demo](https://codspeed.io/readme-video.gif)](https://codspeed.io/?utm_source=github-readme)
24+
[![Video Demo](./assets/readme-video.gif)](https://codspeed.io/?utm_source=github-readme)
2425

2526
# Key features
2627

@@ -38,39 +39,57 @@
3839
curl -fsSL https://codspeed.io/install.sh | bash
3940
```
4041

41-
## Usage
42-
4342
> [!NOTE]
44-
> For now, the CLI only supports Ubuntu 20.04, 22.04, 24.04 and Debian 11, 12.
43+
> The CodSpeed CLI officially supports Ubuntu 20.04, 22.04, 24.04 and Debian 11, 12.
44+
> Other Linux distributions may work, but are not officially supported.
4545
46-
First, authenticate with your CodSpeed account:
46+
## Quick Start
47+
48+
First, authenticate to keep your benchmark results linked to your CodSpeed account:
4749

4850
```bash
4951
codspeed auth login
5052
```
5153

52-
Then, run benchmarks with the following command:
54+
The simplest way to get started is to benchmark any executable program directly:
5355

5456
```bash
55-
codspeed run <my-benchmark-command>
57+
# Benchmark a single command
58+
codspeed exec -- ./my-binary --arg1 value
59+
60+
# Benchmark a script
61+
codspeed exec -- python my_script.py
62+
63+
# Benchmark with specific instrument
64+
codspeed exec --mode walltime -- node app.js
65+
```
66+
67+
This approach requires no code changes and works with any executable. CodSpeed will measure the performance provide the instrument results.
5668

57-
# Example, using https://github.com/CodSpeedHQ/codspeed-rust
69+
## Deeper integration with harnesses using `codspeed run`
70+
71+
For more control and integration with your existing benchmark suite, you can use language-specific harnesses. This allows you to:
72+
73+
- Define multiple benchmarks and keep them versioned in your codebase
74+
- Scope benchmarks to specific functions or modules
75+
- Integrate with existing benchmark suites (pytest, criterion, vitest, etc.)
76+
77+
```bash
78+
# Using the Rust harness with criterion
5879
codspeed run cargo codspeed run
5980

60-
# Example, using https://github.com/CodSpeedHQ/pytest-codspeed
81+
# Using the Python harness with pytest
6182
codspeed run pytest ./tests --codspeed
6283

63-
# Example, using https://github.com/CodSpeedHQ/codspeed-node/tree/main/packages/vitest-plugin
84+
# Using the Node.js harness with vitest
6485
codspeed run pnpm vitest bench
6586
```
6687

67-
## In CI environments
68-
69-
To run CodSpeed in Github Actions, we recommend using our official GitHub Action: [@CodSpeedHQ/action](https://github.com/CodSpeedHQ/action).
88+
These harnesses provide deeper instrumentation and allow you to write benchmarks using familiar testing frameworks.
7089

71-
## Languages Integrations
90+
### Languages Integrations
7291

73-
On top of the generic CLI, CodSpeed provides first-class integrations for multiple languages and frameworks:
92+
CodSpeed provides first-class integrations for multiple languages and frameworks:
7493

7594
| Language | Repository | Supported Frameworks |
7695
| --------------- | ---------------------------------------------------------------- | ------------------------------------- |
@@ -83,30 +102,155 @@ On top of the generic CLI, CodSpeed provides first-class integrations for multip
83102

84103
Need to bench another language or framework? Open [an issue](https://github.com/CodSpeedHQ/codspeed/issues) or let us know on [Discord](https://codspeed.io/discord)!
85104

86-
## Advanced usage
105+
### CLI Harness: `codspeed.yml` configuration
106+
107+
The CLI also offers a built-in harness that allows you to define benchmarks directly.
108+
109+
You can define multiple `codspeed exec` benchmark targets and configure options in a `codspeed.yml` file.
110+
This is useful when you want to benchmark several commands with different configurations.
111+
112+
Create a `codspeed.yml` file in your project root:
113+
114+
```yaml
115+
# Global options applied to all benchmarks
116+
options:
117+
warmup-time: "0.2s"
118+
max-time: 1s
119+
120+
# List of benchmarks to run
121+
benchmarks:
122+
- name: "Fast operation"
123+
exec: ./my_binary --mode fast
124+
options:
125+
max-rounds: 20
126+
127+
- name: "Slow operation"
128+
exec: ./my_binary --mode slow
129+
options:
130+
max-time: 200ms
131+
132+
- name: "Script benchmark"
133+
exec: python scripts/benchmark.py
134+
```
135+
136+
Then run all benchmarks with:
137+
138+
```bash
139+
codspeed run --mode walltime
140+
```
141+
142+
> [!TIP]
143+
> For more details on configuration options, see the [CLI documentation](https://codspeed.io/docs/cli).
87144
88-
### Installing tools before running
145+
## Performance Instruments
89146

90-
You can install executors and instruments before running the benchmark with the `setup` command:
147+
CodSpeed provides multiple instruments to measure different aspects of your code's performance. Choose the one that best fits your use case:
148+
149+
### CPU Simulation
150+
151+
Simulates CPU behavior for **<1% variance** regardless of system load. Hardware-agnostic measurements with automatic flame graphs.
152+
153+
**Best for:** CPU-intensive code, CI regression detection, cross-platform comparison
91154

92155
```bash
93-
codspeed setup
156+
codspeed exec --mode simulation -- ./my-binary
94157
```
95158

96-
This is especially useful when configuring environments with tools such as docker.
159+
### Memory
160+
161+
Tracks heap allocations (peak usage, count, allocation size) with eBPF profiling.
97162

98-
### Changing the mode of the runner
163+
**Best for:** Memory optimization, leak detection, constrained environments
99164

100-
By default, the runner will run the benchmark in the `simulation` mode. You can specify the mode with the `--mode` flag of the `run` command:
165+
**Supported:** Rust, C/C++ with libc, jemalloc, mimalloc
101166

102167
```bash
103-
# Run in the `simulation` mode
104-
codspeed run --mode simulation <my-benchmark-command>
168+
codspeed exec --mode memory -- ./my-binary
169+
```
170+
171+
### Walltime
172+
173+
Measures real-world execution time including I/O, system calls, and multi-threading effects.
105174

106-
# Run in the `walltime` mode
107-
codspeed run --mode walltime <my-benchmark-command>
175+
**Best for:** API tests, I/O-heavy workloads, multi-threaded applications
176+
177+
```bash
178+
codspeed exec --mode walltime -- ./my-api-test
108179
```
109180

110181
> [!WARNING]
111182
> Using the `walltime` mode on traditional VMs/Hosted Runners will lead to inconsistent data. For the best results, we recommend using CodSpeed Hosted Macro Runners, which are fine-tuned for performance measurement consistency.
112183
> Check out the [Walltime Instrument Documentation](https://docs.codspeed.io/instruments/walltime/) for more details.
184+
185+
> [!TIP]
186+
> For detailed information on each instrument, see the [Instruments documentation](https://codspeed.io/docs/instruments).
187+
188+
## Usage In CI environments
189+
190+
Running CodSpeed in CI allows you to automatically detect performance regressions on every pull request and track performance evolution over time.
191+
192+
### GitHub Actions
193+
194+
We recommend using our official GitHub Action: [@CodSpeedHQ/action](https://github.com/CodSpeedHQ/action).
195+
196+
Here is a sample `.github/workflows/codspeed.yml` workflow for Python:
197+
198+
```yaml
199+
name: CodSpeed Benchmarks
200+
201+
on:
202+
push:
203+
branches:
204+
- "main" # or "master"
205+
pull_request:
206+
workflow_dispatch:
207+
208+
permissions:
209+
contents: read
210+
id-token: write
211+
212+
jobs:
213+
benchmarks:
214+
runs-on: ubuntu-latest
215+
steps:
216+
- uses: actions/checkout@v4
217+
218+
# Set up your language/environment here
219+
# For Python:
220+
- uses: actions/setup-python@v5
221+
with:
222+
python-version: "3.12"
223+
- run: pip install -r requirements.txt
224+
225+
# Run benchmarks with CodSpeed
226+
- uses: CodSpeedHQ/action@v4
227+
with:
228+
mode: instrumentation
229+
run: pytest tests/ --codspeed
230+
```
231+
232+
### GitLab CI
233+
234+
Here is a sample `.gitlab-ci.yml` configuration for Python:
235+
236+
```yaml
237+
workflow:
238+
rules:
239+
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
240+
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
241+
242+
codspeed:
243+
stage: test
244+
image: python:3.12
245+
id_tokens:
246+
CODSPEED_TOKEN:
247+
aud: codspeed.io
248+
before_script:
249+
- pip install -r requirements.txt
250+
- curl -fsSL https://codspeed.io/install.sh | bash -s -- --quiet
251+
script:
252+
- codspeed run --mode simulation -- pytest tests/ --codspeed
253+
```
254+
255+
> [!TIP]
256+
> For more CI integration examples and advanced configurations, check out the [CI Integration Documentation](https://codspeed.io/docs/integrations/ci/).

assets/readme-video.gif

Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)