Skip to content

Commit e033746

Browse files
sddart049
authored andcommitted
feat(criterion): BenchmarkGroup compat with Measurement generic param and plot_config
1 parent 267cb38 commit e033746

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

crates/criterion_compat/src/compat/criterion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ impl<M: Measurement> Criterion<M> {
7878
self
7979
}
8080

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

crates/criterion_compat/src/compat/group.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1+
use std::marker::PhantomData;
12
use std::{cell::RefCell, rc::Rc, time::Duration};
23

34
use codspeed::{codspeed::CodSpeed, utils::get_git_relative_path};
4-
use criterion::{measurement::Measurement, SamplingMode, Throughput};
5+
use criterion::{measurement::Measurement, PlotConfiguration, SamplingMode, Throughput};
56

67
use crate::{Bencher, Criterion};
78

8-
pub struct BenchmarkGroup {
9+
pub struct BenchmarkGroup<M: Measurement> {
910
codspeed: Rc<RefCell<CodSpeed>>,
1011
current_file: String,
1112
macro_group: String,
1213
group_name: String,
14+
phantom: PhantomData<*const M>,
1315
}
1416

15-
impl BenchmarkGroup {
16-
pub fn new<M: Measurement>(criterion: &mut Criterion<M>, group_name: String) -> BenchmarkGroup {
17-
BenchmarkGroup {
17+
impl<M: Measurement> BenchmarkGroup<M> {
18+
pub fn new(criterion: &mut Criterion<M>, group_name: String) -> BenchmarkGroup<M> {
19+
BenchmarkGroup::<M> {
1820
codspeed: criterion
1921
.codspeed
2022
.as_ref()
@@ -23,6 +25,7 @@ impl BenchmarkGroup {
2325
current_file: criterion.current_file.clone(),
2426
macro_group: criterion.macro_group.clone(),
2527
group_name,
28+
phantom: PhantomData,
2629
}
2730
}
2831

@@ -73,7 +76,7 @@ impl BenchmarkGroup {
7376

7477
// Dummy methods
7578
#[allow(unused_variables)]
76-
impl BenchmarkGroup {
79+
impl<M: Measurement> BenchmarkGroup<M> {
7780
pub fn sample_size(&mut self, n: usize) -> &mut Self {
7881
self
7982
}
@@ -101,6 +104,9 @@ impl BenchmarkGroup {
101104
pub fn sampling_mode(&mut self, new_mode: SamplingMode) -> &mut Self {
102105
self
103106
}
107+
pub fn plot_config(&mut self, new_config: PlotConfiguration) -> &mut Self {
108+
self
109+
}
104110
pub fn finish(self) {}
105111
}
106112

0 commit comments

Comments
 (0)