Skip to content

fix: fix relative path when using working-directory #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 27, 2023
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
17 changes: 8 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- uses: actions-rs/toolchain@v1
- uses: moonrepo/setup-rust@v0
with:
toolchain: stable
channel: stable
components: clippy
- uses: pre-commit/[email protected]
with:
Expand All @@ -24,20 +23,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- uses: actions-rs/toolchain@v1
- uses: moonrepo/setup-rust@v0
with:
toolchain: stable
channel: stable
- run: cargo test --all

compat-integration-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
- uses: moonrepo/setup-rust@v0
with:
toolchain: stable
- uses: Swatinem/rust-cache@v2
channel: stable
cache-target: release

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

- run: cargo codspeed build -p codspeed
Expand Down
92 changes: 55 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion crates/bencher_compat/benches/bencher_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,20 @@ pub fn b(bench: &mut Bencher) {
bench.bytes = N as u64;
}

benchmark_group!(benches, a, b);
mod c {
use super::*;

pub fn a(bench: &mut Bencher) {
bench.iter(|| (0..100).fold(0, |x, y| black_box(x + y)))
}

pub fn b(bench: &mut Bencher) {
const N: usize = 1024;
bench.iter(|| vec![0u8; N]);

bench.bytes = N as u64;
}
}

benchmark_group!(benches, a, b, c::a, c::b);
benchmark_main!(benches);
30 changes: 21 additions & 9 deletions crates/bencher_compat/src/compat.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
use codspeed::codspeed::{black_box, CodSpeed, WARMUP_RUNS};
use codspeed::{
codspeed::{black_box, CodSpeed, WARMUP_RUNS},
utils::{get_formated_function_path, get_git_relative_path},
};

pub struct Bencher {
pub bytes: u64,
codspeed: CodSpeed,
current_uri: String,
current_file: String,
current_bench_path: String,
}

impl Bencher {
pub fn set_current_uri(&mut self, uri: String) {
self.current_uri = uri;
pub fn set_current_file(&mut self, file: impl Into<String>) {
self.current_file = file.into();
}

pub fn set_current_bench_path(&mut self, bench: impl Into<String>) {
self.current_bench_path = bench.into();
}

pub fn push_group(&mut self, group: &str) {
Expand All @@ -23,11 +31,13 @@ impl Bencher {
where
F: FnMut() -> T,
{
let uri = self.current_uri.as_str();
let file = get_git_relative_path(self.current_file.as_str());
let bench_path = get_formated_function_path(self.current_bench_path.as_str());
let uri = format!("{}::{}", file.to_string_lossy(), bench_path);
for _ in 0..WARMUP_RUNS {
black_box(inner());
}
self.codspeed.start_benchmark(uri);
self.codspeed.start_benchmark(uri.as_str());
black_box(inner());
self.codspeed.end_benchmark();
}
Expand All @@ -42,18 +52,20 @@ impl Default for Bencher {
Bencher {
bytes: 0,
codspeed: CodSpeed::new(),
current_uri: String::new(),
current_file: String::new(),
current_bench_path: String::new(),
}
}
}

#[macro_export]
macro_rules! benchmark_group {
($group_name:ident, $($function:path),+) => {
($group_name:ident, $( $function:path ),+ $(,)*) => {
pub fn $group_name(bencher: &mut $crate::Bencher) {
bencher.push_group(stringify!($group_name));
$(
bencher.set_current_uri($crate::codspeed_uri!($function));
bencher.set_current_file($crate::abs_file!());
bencher.set_current_bench_path(stringify!($function));
$function(bencher);
)+
bencher.pop_group();
Expand Down
4 changes: 2 additions & 2 deletions crates/bencher_compat/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
pub use codspeed::codspeed_uri;

#[cfg(not(codspeed))]
mod compat_bencher {
pub use bencher::*;
Expand All @@ -8,6 +6,8 @@ mod compat_bencher {
#[cfg(codspeed)]
#[path = "."]
mod compat_bencher {
pub use codspeed::abs_file;

mod compat;
pub use compat::*;
}
Expand Down
Loading