Skip to content

Commit

Permalink
feat(criterion): BenchmarkGroup compat with Measurement generic p…
Browse files Browse the repository at this point in the history
…aram and `plot_config`
  • Loading branch information
sdd authored and art049 committed Nov 14, 2023
1 parent 267cb38 commit e033746
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions crates/criterion_compat/src/compat/criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ impl<M: Measurement> Criterion<M> {
self
}

pub fn benchmark_group<S: Into<String>>(&mut self, group_name: S) -> BenchmarkGroup {
BenchmarkGroup::new(self, group_name.into())
pub fn benchmark_group<S: Into<String>>(&mut self, group_name: S) -> BenchmarkGroup<M> {
BenchmarkGroup::<M>::new(self, group_name.into())
}
}

Expand Down
18 changes: 12 additions & 6 deletions crates/criterion_compat/src/compat/group.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
use std::marker::PhantomData;
use std::{cell::RefCell, rc::Rc, time::Duration};

use codspeed::{codspeed::CodSpeed, utils::get_git_relative_path};
use criterion::{measurement::Measurement, SamplingMode, Throughput};
use criterion::{measurement::Measurement, PlotConfiguration, SamplingMode, Throughput};

use crate::{Bencher, Criterion};

pub struct BenchmarkGroup {
pub struct BenchmarkGroup<M: Measurement> {
codspeed: Rc<RefCell<CodSpeed>>,
current_file: String,
macro_group: String,
group_name: String,
phantom: PhantomData<*const M>,
}

impl BenchmarkGroup {
pub fn new<M: Measurement>(criterion: &mut Criterion<M>, group_name: String) -> BenchmarkGroup {
BenchmarkGroup {
impl<M: Measurement> BenchmarkGroup<M> {
pub fn new(criterion: &mut Criterion<M>, group_name: String) -> BenchmarkGroup<M> {
BenchmarkGroup::<M> {
codspeed: criterion
.codspeed
.as_ref()
Expand All @@ -23,6 +25,7 @@ impl BenchmarkGroup {
current_file: criterion.current_file.clone(),
macro_group: criterion.macro_group.clone(),
group_name,
phantom: PhantomData,
}
}

Expand Down Expand Up @@ -73,7 +76,7 @@ impl BenchmarkGroup {

// Dummy methods
#[allow(unused_variables)]
impl BenchmarkGroup {
impl<M: Measurement> BenchmarkGroup<M> {
pub fn sample_size(&mut self, n: usize) -> &mut Self {
self
}
Expand Down Expand Up @@ -101,6 +104,9 @@ impl BenchmarkGroup {
pub fn sampling_mode(&mut self, new_mode: SamplingMode) -> &mut Self {
self
}
pub fn plot_config(&mut self, new_config: PlotConfiguration) -> &mut Self {
self
}
pub fn finish(self) {}
}

Expand Down

0 comments on commit e033746

Please sign in to comment.