Skip to content

Commit 1f62ee3

Browse files
committed
feat: install codspeed
1 parent ffbd2e3 commit 1f62ee3

4 files changed

Lines changed: 64 additions & 7 deletions

File tree

.github/workflows/codspeed.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: CodSpeed Benchmarks
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
id-token: write
13+
14+
jobs:
15+
benchmarks:
16+
name: Run benchmarks
17+
runs-on: codspeed-macro
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Setup Rust
22+
uses: dtolnay/rust-toolchain@stable
23+
with:
24+
toolchain: 1.83.0
25+
26+
- name: Cache cargo registry
27+
uses: actions/cache@v4
28+
with:
29+
path: ~/.cargo/registry
30+
key: cargo-registry-${{ runner.arch }}-${{ hashFiles('**/Cargo.lock') }}
31+
restore-keys: |
32+
cargo-registry-${{ runner.arch }}-
33+
34+
- name: Cache target directory
35+
uses: actions/cache@v4
36+
with:
37+
path: target
38+
key: cargo-target-${{ runner.arch }}-${{ hashFiles('**/Cargo.lock') }}
39+
restore-keys: |
40+
cargo-target-${{ runner.arch }}-
41+
42+
- name: Install cargo-codspeed
43+
run: cargo install cargo-codspeed --locked
44+
45+
- name: Build benchmarks
46+
run: cargo codspeed build
47+
48+
- name: Run benchmarks
49+
uses: CodSpeedHQ/action@v4
50+
with:
51+
mode: walltime
52+
run: cargo codspeed run

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Cargo.lock
1212
# OS files
1313
.DS_Store
1414
Thumbs.db
15+
target

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2021"
66
[dependencies]
77

88
[dev-dependencies]
9-
divan = "0.1"
9+
divan = { package = "codspeed-divan-compat", version = "4.2.1" }
1010

1111
[[bench]]
1212
name = "particle_simulation"

benches/particle_simulation.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ fn main() {
44
divan::main();
55
}
66

7+
const SMALL: usize = 100_000;
8+
const MEDIUM: usize = 1_000_000;
9+
const LARGE: usize = 10_000_000;
10+
711
// ============================================================================
812
// Array of Structures (AoS) - Cache Unfriendly
913
// ============================================================================
1014

11-
#[divan::bench(args = [1_000, 10_000, 100_000])]
15+
#[divan::bench(args = [SMALL, MEDIUM, LARGE])]
1216
fn aos_update_positions(bencher: divan::Bencher, count: usize) {
1317
bencher
1418
.with_inputs(|| aos::ParticleSystem::new(count))
@@ -17,7 +21,7 @@ fn aos_update_positions(bencher: divan::Bencher, count: usize) {
1721
});
1822
}
1923

20-
#[divan::bench(args = [1_000, 10_000, 100_000])]
24+
#[divan::bench(args = [SMALL, MEDIUM, LARGE])]
2125
fn aos_kinetic_energy(bencher: divan::Bencher, count: usize) {
2226
bencher
2327
.with_inputs(|| aos::ParticleSystem::new(count))
@@ -26,7 +30,7 @@ fn aos_kinetic_energy(bencher: divan::Bencher, count: usize) {
2630
});
2731
}
2832

29-
#[divan::bench(args = [1_000, 10_000, 100_000])]
33+
#[divan::bench(args = [SMALL, MEDIUM, LARGE])]
3034
fn aos_apply_gravity(bencher: divan::Bencher, count: usize) {
3135
bencher
3236
.with_inputs(|| aos::ParticleSystem::new(count))
@@ -39,7 +43,7 @@ fn aos_apply_gravity(bencher: divan::Bencher, count: usize) {
3943
// Structure of Arrays - Cache Friendly
4044
// ============================================================================
4145

42-
#[divan::bench(args = [1_000, 10_000, 100_000])]
46+
#[divan::bench(args = [SMALL, MEDIUM, LARGE])]
4347
fn soa_update_positions(bencher: divan::Bencher, count: usize) {
4448
bencher
4549
.with_inputs(|| soa::ParticleSystem::new(count))
@@ -48,7 +52,7 @@ fn soa_update_positions(bencher: divan::Bencher, count: usize) {
4852
});
4953
}
5054

51-
#[divan::bench(args = [1_000, 10_000, 100_000])]
55+
#[divan::bench(args = [SMALL, MEDIUM, LARGE])]
5256
fn soa_kinetic_energy(bencher: divan::Bencher, count: usize) {
5357
bencher
5458
.with_inputs(|| soa::ParticleSystem::new(count))
@@ -57,7 +61,7 @@ fn soa_kinetic_energy(bencher: divan::Bencher, count: usize) {
5761
});
5862
}
5963

60-
#[divan::bench(args = [1_000, 10_000, 100_000])]
64+
#[divan::bench(args = [SMALL, MEDIUM, LARGE])]
6165
fn soa_apply_gravity(bencher: divan::Bencher, count: usize) {
6266
bencher
6367
.with_inputs(|| soa::ParticleSystem::new(count))

0 commit comments

Comments
 (0)