|
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; |
4 | 6 |
|
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::*; |
8 | 10 |
|
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 | + ); |
16 | 18 |
|
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 | + } |
23 | 27 | }
|
24 |
| - } |
25 |
| -} |
26 | 28 |
|
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); |
29 | 31 |
|
30 |
| - fill_plane(ra, &mut p); |
| 32 | + fill_plane(ra, &mut p); |
31 | 33 |
|
32 |
| - p |
33 |
| -} |
| 34 | + p |
| 35 | + } |
34 | 36 |
|
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 | + ]; |
47 | 47 |
|
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 | + } |
60 | 60 |
|
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 | + ]; |
73 | 71 |
|
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 | + } |
86 | 84 |
|
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 | + ]; |
99 | 95 |
|
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 | + } |
112 | 108 |
|
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 | + ]; |
125 | 119 |
|
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 | + } |
137 | 133 | }
|
0 commit comments