Skip to content

Commit 4675887

Browse files
committed
Update benches for 4-width
1 parent d9380e4 commit 4675887

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

benches/conversions.rs

+34-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use colcon::Space;
22
use criterion::{black_box, criterion_group, criterion_main, Criterion};
33

4-
fn pixels() -> Vec<f32> {
4+
fn pixels<const N: usize>() -> Vec<f32> {
55
let size = 512;
66
let mut result = Vec::<f32>::with_capacity(size * size * 3);
77
for x in 1..=size {
88
for y in 1..=size {
99
let n = (x as f32 / size as f32 / 2.0) + (y as f32 / size as f32 / 2.0);
10-
result.extend_from_slice(&[n; 3]);
10+
result.extend_from_slice(&[n; N]);
1111
}
1212
}
1313
result
@@ -58,51 +58,74 @@ macro_rules! bench_convert_generic {
5858
$c.bench_function(concat!($id, "_", $n, $ts, "_slice"), |b| {
5959
b.iter(|| {
6060
let mut pixels = $ps.clone();
61-
black_box(colcon::convert_space_sliced($from, $to, &mut pixels));
61+
black_box(colcon::convert_space_sliced::<_, 3>($from, $to, &mut pixels));
6262
})
6363
});
6464
};
6565
}
6666

6767
pub fn conversions(c: &mut Criterion) {
68-
let pix_slice_f32: Box<[f32]> = pixels().into_boxed_slice();
68+
let pix_slice_3f32: Box<[f32]> = pixels::<3>().into_boxed_slice();
69+
let pix_slice_4f32: Box<[f32]> = pixels::<4>().into_boxed_slice();
6970

70-
let pix_slice_f64: Box<[f64]> = pixels()
71+
let pix_slice_3f64: Box<[f64]> = pixels::<3>()
7172
.into_iter()
7273
.map(|c| c.into())
7374
.collect::<Vec<f64>>()
7475
.into_boxed_slice();
7576

76-
let pix_chunk_3f32: Box<[[f32; 3]]> = pixels()
77+
let pix_slice_4f64: Box<[f64]> = pixels::<4>()
78+
.into_iter()
79+
.map(|c| c.into())
80+
.collect::<Vec<f64>>()
81+
.into_boxed_slice();
82+
83+
let pix_chunk_3f32: Box<[[f32; 3]]> = pixels::<3>()
7784
.chunks_exact(3)
7885
.map(|c| c.try_into().unwrap())
7986
.collect::<Vec<[f32; 3]>>()
8087
.into_boxed_slice();
8188

82-
let pix_chunk_3f64: Box<[[f64; 3]]> = pixels()
89+
let pix_chunk_4f32: Box<[[f32; 4]]> = pixels::<4>()
90+
.chunks_exact(4)
91+
.map(|c| c.try_into().unwrap())
92+
.collect::<Vec<[f32; 4]>>()
93+
.into_boxed_slice();
94+
95+
let pix_chunk_3f64: Box<[[f64; 3]]> = pixels::<3>()
8396
.chunks_exact(3)
8497
.map(|c| TryInto::<[f32; 3]>::try_into(c).unwrap().map(|n| n.into()))
8598
.collect::<Vec<[f64; 3]>>()
8699
.into_boxed_slice();
87100

101+
let pix_chunk_4f64: Box<[[f64; 4]]> = pixels::<4>()
102+
.chunks_exact(4)
103+
.map(|c| TryInto::<[f32; 4]>::try_into(c).unwrap().map(|n| n.into()))
104+
.collect::<Vec<[f64; 4]>>()
105+
.into_boxed_slice();
106+
88107
macro_rules! bench_three {
89108
($f: path, $id:literal) => {
90109
bench_three_generic!(c, pix_chunk_3f32, $f, $id, 3, f32, "f32");
91110
bench_three_generic!(c, pix_chunk_3f64, $f, $id, 3, f64, "f64");
111+
bench_three_generic!(c, pix_chunk_4f32, $f, $id, 4, f32, "f32");
112+
bench_three_generic!(c, pix_chunk_4f64, $f, $id, 4, f64, "f64");
92113
};
93114
}
94115

95116
macro_rules! bench_one {
96117
($f: path, $id:literal) => {
97-
bench_one_generic!(c, pix_slice_f32, $f, $id, f32, "f32");
98-
bench_one_generic!(c, pix_slice_f32, $f, $id, f64, "f64");
118+
bench_one_generic!(c, pix_slice_3f32, $f, $id, f32, "f32");
119+
bench_one_generic!(c, pix_slice_3f32, $f, $id, f64, "f64");
99120
};
100121
}
101122

102123
macro_rules! bench_convert {
103124
($from: expr, $to:expr, $id:literal) => {
104-
bench_convert_generic!(c, pix_slice_f32, pix_chunk_3f32, $from, $to, $id, 3, f32, "f32");
105-
bench_convert_generic!(c, pix_slice_f64, pix_chunk_3f64, $from, $to, $id, 3, f64, "f64");
125+
bench_convert_generic!(c, pix_slice_3f32, pix_chunk_3f32, $from, $to, $id, 3, f32, "f32");
126+
bench_convert_generic!(c, pix_slice_3f64, pix_chunk_3f64, $from, $to, $id, 3, f64, "f64");
127+
bench_convert_generic!(c, pix_slice_4f32, pix_chunk_4f32, $from, $to, $id, 4, f32, "f32");
128+
bench_convert_generic!(c, pix_slice_4f64, pix_chunk_4f64, $from, $to, $id, 4, f64, "f64");
106129
};
107130
}
108131

0 commit comments

Comments
 (0)