Skip to content

Commit ef4e3c3

Browse files
committed
chore: update crate readmes
1 parent a5d1e01 commit ef4e3c3

File tree

5 files changed

+205
-7
lines changed

5 files changed

+205
-7
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
# codspeed-rust
1+
<div align="center">
2+
<h1>codspeed-rust</h1>
3+
4+
[![CI](https://github.com/CodSpeedHQ/codspeed-rust/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/CodSpeedHQ/codspeed-rust/actions/workflows/ci.yml)
5+
![Crates.io](https://img.shields.io/crates/v/cargo-codspeed)
6+
7+
</div>
28

39
This mono-repo contains the integration crates for using CodSpeed in Rust:
410

crates/bencher_compat/README.md

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,79 @@
1-
# codspeed-bencher-compat
1+
<div align="center">
2+
<h1>codspeed-bencher-compat</h1>
3+
4+
[![CI](https://github.com/CodSpeedHQ/codspeed-rust/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/CodSpeedHQ/codspeed-rust/actions/workflows/ci.yml)
5+
![Crates.io](https://img.shields.io/crates/v/codspeed-bencher-compat)
6+
7+
Bencher compatibility layer for CodSpeed
8+
9+
</div>
10+
11+
## Installation
12+
13+
```sh
14+
cargo add --dev codspeed-bencher-compat
15+
```
16+
17+
## Usage
18+
19+
Let's start with the example from the [Bencher documentation](https://docs.rs/bencher/latest/bencher/),
20+
creating a benchmark suite for 2 simple functions (in `benches/example.rs`):
21+
22+
```rust
23+
use bencher::{benchmark_group, benchmark_main, Bencher};
24+
25+
fn a(bench: &mut Bencher) {
26+
bench.iter(|| {
27+
(0..1000).fold(0, |x, y| x + y)
28+
})
29+
}
30+
31+
fn b(bench: &mut Bencher) {
32+
const N: usize = 1024;
33+
bench.iter(|| {
34+
vec![0u8; N]
35+
});
36+
37+
bench.bytes = N as u64;
38+
}
39+
40+
benchmark_group!(benches, a, b);
41+
benchmark_main!(benches);
42+
```
43+
44+
The last step in creating the Bencher benchmark is to add the new benchmark target in your `Cargo.toml`:
45+
46+
```toml title="Cargo.toml"
47+
[[bench]]
48+
name = "example"
49+
harness = false
50+
```
51+
52+
### Plugging CodSpeed
53+
54+
To allow CodSpeed to interact with this suite as well, you simply need to replace
55+
the imports from the `bencher` crate to the `codspeed-bencher-compat` crate:
56+
57+
```diff
58+
- use bencher::{benchmark_group, benchmark_main, Bencher};
59+
+ use codspeed_bencher_compat::{benchmark_group, benchmark_main, Bencher};
60+
```
61+
62+
And that's it! You can now run your benchmark suite with CodSpeed:
63+
64+
```
65+
$ cargo codspeed build
66+
Finished release [optimized] target(s) in 0.12s
67+
Finished built 1 benchmark suite(s)
68+
69+
$ cargo codspeed run
70+
Collected 1 benchmark suite(s) to run
71+
Running example
72+
Using codspeed-bencher-compat v1.0.0 compatibility layer
73+
NOTICE: codspeed is enabled, but no performance measurement will
74+
be made since it's running in an unknown environment.
75+
Checked: benches/example.rs::a (group: benches)
76+
Checked: benches/example.rs::b (group: benches)
77+
Done running bencher_example
78+
Finished running 1 benchmark suite(s)
79+
```

crates/cargo-codspeed/README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
1-
# cargo-codspeed
1+
<div align="center">
2+
<h1>cargo-codspeed</h1>
3+
4+
[![CI](https://github.com/CodSpeedHQ/codspeed-rust/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/CodSpeedHQ/codspeed-rust/actions/workflows/ci.yml)
5+
![Crates.io](https://img.shields.io/crates/v/cargo-codspeed)
6+
7+
A cargo subcommand for running CodSpeed on your project
8+
9+
</div>
10+
11+
## Installation
12+
13+
```bash
14+
cargo install cargo-codspeed
15+
```
16+
17+
## Usage
18+
19+
```
20+
Usage: cargo codspeed <COMMAND>
21+
22+
Commands:
23+
build Build the benchmarks
24+
run Run the previously built benchmarks
25+
26+
Options:
27+
-h, --help Print help information
28+
-V, --version Print version information
29+
```

crates/codspeed/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
# codspeed
1+
<div align="center">
2+
<h1>codspeed</h1>
3+
4+
[![CI](https://github.com/CodSpeedHQ/codspeed-rust/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/CodSpeedHQ/codspeed-rust/actions/workflows/ci.yml)
5+
![Crates.io](https://img.shields.io/crates/v/codspeed)
6+
7+
The core library used to integrate with Codspeed runners
8+
9+
</div>
10+
11+
For now, this crate should not be used directly. Instead, use one of the integration crates:
12+
13+
- `codspeed-bencher-compat`
14+
- `codspeed-criterion-compat`

crates/criterion_compat/README.md

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,78 @@
1-
# codspeed-criterion-compat
1+
<div align="center">
2+
<h1>codspeed-criterion-compat</h1>
23

3-
### Not supported yet
4+
[![CI](https://github.com/CodSpeedHQ/codspeed-rust/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/CodSpeedHQ/codspeed-rust/actions/workflows/ci.yml)
5+
![Crates.io](https://img.shields.io/crates/v/codspeed-criterion-compat)
46

5-
- AsyncBencher (Criterion)
7+
Criterion.rs compatibility layer for CodSpeed
8+
9+
</div>
10+
11+
## Installation
12+
13+
```sh
14+
cargo add --dev codspeed-criterion-compat
15+
```
16+
17+
## Usage
18+
19+
Let's start with the example from the [Criterion.rs documentation](https://bheisler.github.io/criterion.rs/book/getting_started.html),
20+
creating a benchmark suite for the Fibonacci function (in `benches/my_benchmark.rs`):
21+
22+
```rust
23+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
24+
25+
fn fibonacci(n: u64) -> u64 {
26+
match n {
27+
0 => 1,
28+
1 => 1,
29+
n => fibonacci(n-1) + fibonacci(n-2),
30+
}
31+
}
32+
33+
pub fn criterion_benchmark(c: &mut Criterion) {
34+
c.bench_function("fib 20", |b| b.iter(|| fibonacci(black_box(20))));
35+
}
36+
37+
criterion_group!(benches, criterion_benchmark);
38+
criterion_main!(benches);
39+
```
40+
41+
The last step in creating the Criterion benchmark is to add the new benchmark target in your `Cargo.toml`:
42+
43+
```toml title="Cargo.toml"
44+
[[bench]]
45+
name = "my_benchmark"
46+
harness = false
47+
```
48+
49+
### Plugging CodSpeed
50+
51+
To allow CodSpeed to interact with this suite as well, you simply need to replace
52+
the imports from the `criterion` crate to the `codspeed-criterion-compat` crate:
53+
54+
```diff
55+
- use criterion::{black_box, criterion_group, criterion_main, Criterion};
56+
+ use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Criterion};
57+
```
58+
59+
And that's it! You can now run your benchmark suite with `cargo-codspeed`:
60+
61+
```
62+
$ cargo codspeed build
63+
Finished release [optimized] target(s) in 0.12s
64+
Finished built 1 benchmark suite(s)
65+
66+
$ cargo codspeed run
67+
Collected 1 benchmark suite(s) to run
68+
Running my_benchmark
69+
Using codspeed-criterion-compat v1.0.0 compatibility layer
70+
NOTICE: codspeed is enabled, but no performance measurement will be made since it's running in an unknown environment.
71+
Checked: benches/bencher_example.rs::fib_20 (group: benches)
72+
Done running bencher_example
73+
Finished running 1 benchmark suite(s)
74+
```
75+
76+
### Not supported yet:
77+
78+
- AsyncBencher

0 commit comments

Comments
 (0)