Skip to content
Closed
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
62 changes: 32 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,44 +59,45 @@ jobs:
- uses: moonrepo/setup-rust@v1
- run: cargo test --all

compat-integration-test-instrumentation:
runs-on: ubuntu-latest
strategy:
matrix:
build-args:
- "-p codspeed"
- "-p codspeed-bencher-compat"
- "--features async_futures -p codspeed-criterion-compat"
- "-p codspeed-divan-compat"
- "-p codspeed-divan-compat-examples"
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: moonrepo/setup-rust@v1
with:
cache-target: release
# compat-integration-test-instrumentation:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# build-args:
# - "-p codspeed"
# - "-p codspeed-bencher-compat"
# - "--features async_futures -p codspeed-criterion-compat"
# - "-p codspeed-divan-compat"
# - "-p codspeed-divan-compat-examples"
# steps:
# - uses: actions/checkout@v4
# with:
# submodules: true
# - uses: moonrepo/setup-rust@v1
# with:
# cache-target: release

- run: cargo install --path crates/cargo-codspeed --locked
# - run: cargo install --path crates/cargo-codspeed --locked

- run: cargo codspeed build ${{ matrix.build-args }}
# - run: cargo codspeed build ${{ matrix.build-args }}

- name: Run the benchmarks
uses: CodSpeedHQ/action@main
env:
MY_ENV_VAR: "YES"
with:
run: cargo codspeed run
token: ${{ secrets.CODSPEED_TOKEN }}
# - name: Run the benchmarks
# uses: CodSpeedHQ/action@main
# env:
# MY_ENV_VAR: "YES"
# with:
# mode: instrumentation
# run: cargo codspeed run
# token: ${{ secrets.CODSPEED_TOKEN }}

compat-integration-test-walltime:
runs-on: codspeed-macro
strategy:
matrix:
package:
- codspeed-divan-compat
# - codspeed-divan-compat
- codspeed-divan-compat-examples
- codspeed-criterion-compat
# - codspeed-criterion-compat
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -113,11 +114,13 @@ jobs:
cargo codspeed build -p ${{ matrix.package }}

- name: Run the benchmarks
uses: CodSpeedHQ/action@main
uses: CodSpeedHQ/action@chore/runner-branch
env:
MY_ENV_VAR: "YES"
CODSPEED_PERF_ENABLED: true
with:
runner-branch: cod-1344-investigate-benchmark-time-in-drop_in_place-and-perf
mode: walltime
run: cargo codspeed run
token: ${{ secrets.CODSPEED_TOKEN }}

Expand All @@ -129,7 +132,6 @@ jobs:
- lint-windows
- msrv-check
- tests
- compat-integration-test-instrumentation
- compat-integration-test-walltime
steps:
- uses: re-actors/alls-green@release/v1
Expand Down
30 changes: 15 additions & 15 deletions crates/divan_compat/examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ num-traits = { version = "0.2", optional = true }
default = ["big-math"]
big-math = ["num-bigint", "num-traits"]

[[bench]]
name = "math"
harness = false
# [[bench]]
# name = "math"
# harness = false

[[bench]]
name = "sort"
harness = false
# [[bench]]
# name = "sort"
# harness = false

[[bench]]
name = "time"
harness = false
# [[bench]]
# name = "time"
# harness = false

[[bench]]
name = "time_scale"
harness = false
# [[bench]]
# name = "time_scale"
# harness = false

[[bench]]
name = "env"
harness = false
# [[bench]]
# name = "env"
# harness = false

[[bench]]
name = "the_algorithms"
Expand Down
90 changes: 50 additions & 40 deletions crates/divan_compat/examples/benches/the_algorithms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,28 @@ mod backtracking {

#[divan::bench(args = [4, 5, 6, 7, 8])]
fn n_queens_solver(n: usize) -> Vec<Vec<String>> {
println!("n_queens_solver for n = {}", n);
the_algorithms::backtracking::n_queens_solver(n)
}

// Benchmark parentheses generation with different sizes
#[divan::bench(args = [3, 4, 5, 6])]
fn generate_parentheses(n: usize) -> Vec<String> {
println!("generate_parentheses for n = {}", n);
the_algorithms::backtracking::generate_parentheses(n)
}

// Benchmark combinations generation with different n values, keeping k=3
#[divan::bench(args = [5, 6, 7, 8, 9])]
fn generate_combinations(n: usize) -> Vec<Vec<usize>> {
println!("generate_combinations for n = {}", n);
the_algorithms::backtracking::generate_all_combinations(n, 3).unwrap()
}

// Benchmark graph coloring with different sizes of complete graphs
#[divan::bench(args = [3, 4, 5, 6])]
fn graph_coloring(bencher: divan::Bencher, n: usize) {
println!("graph_coloring for n = {}", n);
// Create a complete graph of size n (all vertices connected to each other)
let matrix = (0..n)
.map(|i| (0..n).map(|j| i != j).collect())
Expand All @@ -44,6 +48,7 @@ mod backtracking {
// Benchmark Hamiltonian cycle finding with different sizes of cyclic graphs
#[divan::bench(args = [4, 5, 6, 7])]
fn hamiltonian_cycle(bencher: divan::Bencher, n: usize) {
println!("hamiltonian_cycle for n = {}", n);
// Create a cyclic graph where each vertex is connected to its neighbors
// This ensures a Hamiltonian cycle exists
let matrix = (0..n)
Expand All @@ -69,6 +74,7 @@ mod backtracking {
// Benchmark Knight's Tour with different board sizes
#[divan::bench(args = [5, 6, 7, 8])]
fn knight_tour(bencher: divan::Bencher, n: usize) {
println!("knight_tour for n = {}", n);
bencher.bench_local(|| {
black_box(the_algorithms::backtracking::find_knight_tour(
black_box(n),
Expand All @@ -82,6 +88,7 @@ mod backtracking {
// Benchmark permutations with different input sizes
#[divan::bench(args = [3, 4, 5, 6, 7])]
fn permutations(bencher: divan::Bencher, n: usize) {
println!("permutations for n = {}", n);
let nums: Vec<isize> = (0..n).map(|x| x as isize).collect();

bencher.bench_local(|| {
Expand All @@ -94,6 +101,7 @@ mod backtracking {
// Benchmark Rat in Maze with different maze sizes
#[divan::bench(args = [5, 6, 7, 8])]
fn rat_in_maze(bencher: divan::Bencher, n: usize) {
println!("rat_in_maze for n = {}", n);
// Create a maze where the rat can move diagonally to the end
let maze = (0..n)
.map(|i| (0..n).map(|j| i == j || i == j + 1).collect())
Expand All @@ -111,6 +119,7 @@ mod backtracking {
// Benchmark Subset Sum with different set sizes
#[divan::bench(args = [10, 12, 14, 16, 18])]
fn subset_sum(bencher: divan::Bencher, n: usize) {
println!("subset_sum for n = {}", n);
let set: Vec<isize> = (0..n).map(|x| x as isize).collect();
let target = (n as isize) * 2; // A challenging but achievable target

Expand All @@ -125,6 +134,7 @@ mod backtracking {
// Benchmark Sudoku solver with different levels of difficulty
#[divan::bench]
fn sudoku(bencher: divan::Bencher) {
println!("sudoku solver benchmark");
// A moderately difficult Sudoku puzzle
let board = [
[3, 0, 6, 5, 0, 8, 4, 0, 0],
Expand All @@ -146,43 +156,43 @@ mod backtracking {
}
}

mod bit_manipulation {
use super::*;

#[divan::bench(args = [0, 42, 255, 1024, 65535])]
fn count_set_bits(bencher: divan::Bencher, n: u32) {
bencher.bench_local(|| {
black_box(the_algorithms::bit_manipulation::count_set_bits(black_box(
n.try_into().unwrap(),
)))
});
}

#[divan::bench(args = [0, 42, 255, 1024, 65535])]
fn find_highest_set_bit(bencher: divan::Bencher, n: u32) {
bencher.bench_local(|| {
black_box(the_algorithms::bit_manipulation::find_highest_set_bit(
black_box(n.try_into().unwrap()),
))
});
}

#[divan::bench(args = [1, 2, 3, 4, 5])]
fn generate_gray_code(bencher: divan::Bencher, n: u32) {
bencher.bench_local(|| {
black_box(the_algorithms::bit_manipulation::generate_gray_code(
black_box(n.try_into().unwrap()),
))
});
}

#[divan::bench(args = &[(0, 0), (42, 13), (255, 255), (1024, -1024), (65535, -65535)])]
fn add_two_integers(bencher: divan::Bencher, (a, b): (i32, i32)) {
bencher.bench_local(|| {
black_box(the_algorithms::bit_manipulation::add_two_integers(
black_box(a.try_into().unwrap()),
black_box(b.try_into().unwrap()),
))
});
}
}
// mod bit_manipulation {
// use super::*;

// #[divan::bench(args = [0, 42, 255, 1024, 65535])]
// fn count_set_bits(bencher: divan::Bencher, n: u32) {
// bencher.bench_local(|| {
// black_box(the_algorithms::bit_manipulation::count_set_bits(black_box(
// n.try_into().unwrap(),
// )))
// });
// }

// #[divan::bench(args = [0, 42, 255, 1024, 65535])]
// fn find_highest_set_bit(bencher: divan::Bencher, n: u32) {
// bencher.bench_local(|| {
// black_box(the_algorithms::bit_manipulation::find_highest_set_bit(
// black_box(n.try_into().unwrap()),
// ))
// });
// }

// #[divan::bench(args = [1, 2, 3, 4, 5])]
// fn generate_gray_code(bencher: divan::Bencher, n: u32) {
// bencher.bench_local(|| {
// black_box(the_algorithms::bit_manipulation::generate_gray_code(
// black_box(n.try_into().unwrap()),
// ))
// });
// }

// #[divan::bench(args = &[(0, 0), (42, 13), (255, 255), (1024, -1024), (65535, -65535)])]
// fn add_two_integers(bencher: divan::Bencher, (a, b): (i32, i32)) {
// bencher.bench_local(|| {
// black_box(the_algorithms::bit_manipulation::add_two_integers(
// black_box(a.try_into().unwrap()),
// black_box(b.try_into().unwrap()),
// ))
// });
// }
// }
Loading