Skip to content

Commit 6cfe34f

Browse files
committed
put benches under features=bench
1 parent 18142f9 commit 6cfe34f

File tree

4 files changed

+419
-403
lines changed

4 files changed

+419
-403
lines changed

benches/bench.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
use criterion::*;
22

3-
mod df;
4-
mod mc;
5-
mod transform;
3+
cfg_if::cfg_if! {
4+
if #[cfg(feature="bench")] {
5+
mod df;
6+
mod mc;
7+
mod transform;
68

7-
criterion_main!(df::df, mc::mc, transform::itdq);
9+
criterion_main!(df::df, mc::mc, transform::itdq);
10+
} else {
11+
fn bench_no_op(_: &mut Criterion) {
12+
}
13+
criterion_group!(
14+
no_op,
15+
bench_no_op,
16+
);
17+
criterion_main!(no_op);
18+
}
19+
}

benches/df.rs

Lines changed: 117 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,133 @@
1-
use criterion::*;
2-
use rand::{Rng, SeedableRng};
3-
use rand_chacha::ChaChaRng;
1+
cfg_if::cfg_if! {
2+
if #[cfg(feature="bench")] {
3+
use criterion::*;
4+
use rand::{Rng, SeedableRng};
5+
use rand_chacha::ChaChaRng;
46

5-
use revc::bench::df::*;
6-
use revc::bench::frame::*;
7-
use revc::bench::plane::*;
7+
use revc::bench::df::*;
8+
use revc::bench::frame::*;
9+
use revc::bench::plane::*;
810

9-
criterion_group!(
10-
df,
11-
bench_deblock_scu_hor_luma,
12-
bench_deblock_scu_hor_chroma,
13-
bench_deblock_scu_ver_luma,
14-
bench_deblock_scu_ver_chroma,
15-
);
11+
criterion_group!(
12+
df,
13+
bench_deblock_scu_hor_luma,
14+
bench_deblock_scu_hor_chroma,
15+
bench_deblock_scu_ver_luma,
16+
bench_deblock_scu_ver_chroma,
17+
);
1618

17-
fn fill_plane<T: Pixel>(ra: &mut ChaChaRng, plane: &mut Plane<T>) {
18-
let stride = plane.cfg.stride;
19-
for row in plane.data_origin_mut().chunks_mut(stride) {
20-
for pixel in row {
21-
let v: u8 = ra.gen();
22-
*pixel = T::cast_from(v);
19+
fn fill_plane<T: Pixel>(ra: &mut ChaChaRng, plane: &mut Plane<T>) {
20+
let stride = plane.cfg.stride;
21+
for row in plane.data_origin_mut().chunks_mut(stride) {
22+
for pixel in row {
23+
let v: u8 = ra.gen();
24+
*pixel = T::cast_from(v);
25+
}
26+
}
2327
}
24-
}
25-
}
2628

27-
fn new_plane<T: Pixel>(ra: &mut ChaChaRng, width: usize, height: usize) -> Plane<T> {
28-
let mut p = Plane::new(width, height, 0, 0, 64 + 16, 64 + 16);
29+
fn new_plane<T: Pixel>(ra: &mut ChaChaRng, width: usize, height: usize) -> Plane<T> {
30+
let mut p = Plane::new(width, height, 0, 0, 64 + 16, 64 + 16);
2931

30-
fill_plane(ra, &mut p);
32+
fill_plane(ra, &mut p);
3133

32-
p
33-
}
34+
p
35+
}
3436

35-
fn bench_deblock_scu_hor_luma(c: &mut Criterion) {
36-
let mut ra = ChaChaRng::from_seed([0; 32]);
37-
let w = 640;
38-
let h = 480;
39-
let cuw = 64;
40-
let cuh = 64;
41-
let qp = 27;
42-
let mut plane = new_plane::<u16>(&mut ra, w, h);
43-
let tbl = &[
44-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
45-
2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12, 12,
46-
];
37+
fn bench_deblock_scu_hor_luma(c: &mut Criterion) {
38+
let mut ra = ChaChaRng::from_seed([0; 32]);
39+
let w = 640;
40+
let h = 480;
41+
let qp = 27;
42+
let mut plane = new_plane::<u16>(&mut ra, w, h);
43+
let tbl = &[
44+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
45+
2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12, 12,
46+
];
4747

48-
c.bench_function("deblock_scu_hor_luma", |b| {
49-
b.iter(|| {
50-
let _ = black_box(deblock_scu_hor_luma(
51-
&mut None,
52-
&mut plane.as_region_mut(),
53-
qp,
54-
0,
55-
tbl,
56-
));
57-
})
58-
});
59-
}
48+
c.bench_function("deblock_scu_hor_luma", |b| {
49+
b.iter(|| {
50+
let _ = black_box(deblock_scu_hor_luma(
51+
&mut None,
52+
&mut plane.as_region_mut(),
53+
qp,
54+
0,
55+
tbl,
56+
));
57+
})
58+
});
59+
}
6060

61-
fn bench_deblock_scu_hor_chroma(c: &mut Criterion) {
62-
let mut ra = ChaChaRng::from_seed([0; 32]);
63-
let w = 640;
64-
let h = 480;
65-
let cuw = 64;
66-
let cuh = 64;
67-
let qp = 27;
68-
let mut plane = new_plane::<u16>(&mut ra, w, h);
69-
let tbl = &[
70-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
71-
2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12, 12,
72-
];
61+
fn bench_deblock_scu_hor_chroma(c: &mut Criterion) {
62+
let mut ra = ChaChaRng::from_seed([0; 32]);
63+
let w = 640;
64+
let h = 480;
65+
let qp = 27;
66+
let mut plane = new_plane::<u16>(&mut ra, w, h);
67+
let tbl = &[
68+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
69+
2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12, 12,
70+
];
7371

74-
c.bench_function("deblock_scu_hor_chroma", |b| {
75-
b.iter(|| {
76-
let _ = black_box(deblock_scu_hor_chroma(
77-
&mut None,
78-
&mut plane.as_region_mut(),
79-
qp,
80-
1,
81-
tbl,
82-
));
83-
})
84-
});
85-
}
72+
c.bench_function("deblock_scu_hor_chroma", |b| {
73+
b.iter(|| {
74+
let _ = black_box(deblock_scu_hor_chroma(
75+
&mut None,
76+
&mut plane.as_region_mut(),
77+
qp,
78+
1,
79+
tbl,
80+
));
81+
})
82+
});
83+
}
8684

87-
fn bench_deblock_scu_ver_luma(c: &mut Criterion) {
88-
let mut ra = ChaChaRng::from_seed([0; 32]);
89-
let w = 640;
90-
let h = 480;
91-
let cuw = 64;
92-
let cuh = 64;
93-
let qp = 27;
94-
let mut plane = new_plane::<u16>(&mut ra, w, h);
95-
let tbl = &[
96-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
97-
2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12, 12,
98-
];
85+
fn bench_deblock_scu_ver_luma(c: &mut Criterion) {
86+
let mut ra = ChaChaRng::from_seed([0; 32]);
87+
let w = 640;
88+
let h = 480;
89+
let qp = 27;
90+
let mut plane = new_plane::<u16>(&mut ra, w, h);
91+
let tbl = &[
92+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
93+
2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12, 12,
94+
];
9995

100-
c.bench_function("deblock_scu_ver_luma", |b| {
101-
b.iter(|| {
102-
let _ = black_box(deblock_scu_ver_luma(
103-
&mut None,
104-
&mut plane.as_region_mut(),
105-
qp,
106-
0,
107-
tbl,
108-
));
109-
})
110-
});
111-
}
96+
c.bench_function("deblock_scu_ver_luma", |b| {
97+
b.iter(|| {
98+
let _ = black_box(deblock_scu_ver_luma(
99+
&mut None,
100+
&mut plane.as_region_mut(),
101+
qp,
102+
0,
103+
tbl,
104+
));
105+
})
106+
});
107+
}
112108

113-
fn bench_deblock_scu_ver_chroma(c: &mut Criterion) {
114-
let mut ra = ChaChaRng::from_seed([0; 32]);
115-
let w = 640;
116-
let h = 480;
117-
let cuw = 64;
118-
let cuh = 64;
119-
let qp = 27;
120-
let mut plane = new_plane::<u16>(&mut ra, w, h);
121-
let tbl = &[
122-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
123-
2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12, 12,
124-
];
109+
fn bench_deblock_scu_ver_chroma(c: &mut Criterion) {
110+
let mut ra = ChaChaRng::from_seed([0; 32]);
111+
let w = 640;
112+
let h = 480;
113+
let qp = 27;
114+
let mut plane = new_plane::<u16>(&mut ra, w, h);
115+
let tbl = &[
116+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
117+
2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12, 12,
118+
];
125119

126-
c.bench_function("deblock_scu_ver_chroma", |b| {
127-
b.iter(|| {
128-
let _ = black_box(deblock_scu_ver_chroma(
129-
&mut None,
130-
&mut plane.as_region_mut(),
131-
qp,
132-
1,
133-
tbl,
134-
));
135-
})
136-
});
120+
c.bench_function("deblock_scu_ver_chroma", |b| {
121+
b.iter(|| {
122+
let _ = black_box(deblock_scu_ver_chroma(
123+
&mut None,
124+
&mut plane.as_region_mut(),
125+
qp,
126+
1,
127+
tbl,
128+
));
129+
})
130+
});
131+
}
132+
}
137133
}

0 commit comments

Comments
 (0)