arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/poulpy-hal/src/bench_suite/vec_znx_big.rs
poulpy-hal/src/bench_suite/vec_znx_big.rsRaw
  1use std::hint::black_box;
  2
  3use criterion::{BenchmarkId, Criterion};
  4use rand::RngCore;
  5
  6use crate::{
  7    api::{
  8        ModuleNew, ScratchOwnedAlloc, ScratchOwnedBorrow, VecZnxBigAdd, VecZnxBigAddInplace, VecZnxBigAddSmall,
  9        VecZnxBigAddSmallInplace, VecZnxBigAlloc, VecZnxBigAutomorphism, VecZnxBigAutomorphismInplace,
 10        VecZnxBigAutomorphismInplaceTmpBytes, VecZnxBigNegate, VecZnxBigNegateInplace, VecZnxBigNormalize,
 11        VecZnxBigNormalizeTmpBytes, VecZnxBigSub, VecZnxBigSubInplace, VecZnxBigSubNegateInplace, VecZnxBigSubSmallA,
 12        VecZnxBigSubSmallB,
 13    },
 14    layouts::{Backend, DataViewMut, Module, ScratchOwned, VecZnx, VecZnxBig},
 15    source::Source,
 16};
 17
 18pub fn bench_vec_znx_big_add<B: Backend>(c: &mut Criterion, label: &str)
 19where
 20    Module<B>: VecZnxBigAdd<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
 21{
 22    let group_name: String = format!("vec_znx_big_add::{label}");
 23
 24    let mut group = c.benchmark_group(group_name);
 25
 26    fn runner<B: Backend>(params: [usize; 3]) -> impl FnMut()
 27    where
 28        Module<B>: VecZnxBigAdd<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
 29    {
 30        let n: usize = params[0];
 31        let cols: usize = params[1];
 32        let size: usize = params[2];
 33
 34        let module: Module<B> = Module::<B>::new(n as u64);
 35
 36        let mut source: Source = Source::new([0u8; 32]);
 37
 38        let mut a: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
 39        let mut b: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
 40        let mut c: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
 41
 42        // Fill a with random bytes
 43        source.fill_bytes(a.data_mut());
 44        source.fill_bytes(b.data_mut());
 45        source.fill_bytes(c.data_mut());
 46
 47        move || {
 48            for i in 0..cols {
 49                module.vec_znx_big_add(&mut c, i, &a, i, &b, i);
 50            }
 51            black_box(());
 52        }
 53    }
 54
 55    for params in [[10, 2, 2], [11, 2, 4], [12, 2, 8], [13, 2, 16], [14, 2, 32]] {
 56        let id: BenchmarkId = BenchmarkId::from_parameter(format!("{}x({}x{})", 1 << params[0], params[1], params[2],));
 57        let mut runner = runner::<B>(params);
 58        group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
 59    }
 60
 61    group.finish();
 62}
 63
 64pub fn bench_vec_znx_big_add_inplace<B: Backend>(c: &mut Criterion, label: &str)
 65where
 66    Module<B>: VecZnxBigAddInplace<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
 67{
 68    let group_name: String = format!("vec_znx_big_add_inplace::{label}");
 69
 70    let mut group = c.benchmark_group(group_name);
 71
 72    fn runner<B: Backend>(params: [usize; 3]) -> impl FnMut()
 73    where
 74        Module<B>: VecZnxBigAddInplace<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
 75    {
 76        let n: usize = params[0];
 77        let cols: usize = params[1];
 78        let size: usize = params[2];
 79
 80        let module: Module<B> = Module::<B>::new(n as u64);
 81
 82        let mut source: Source = Source::new([0u8; 32]);
 83
 84        let mut a: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
 85        let mut c: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
 86
 87        // Fill a with random i64
 88        source.fill_bytes(a.data_mut());
 89        source.fill_bytes(c.data_mut());
 90
 91        move || {
 92            for i in 0..cols {
 93                module.vec_znx_big_add_inplace(&mut c, i, &a, i);
 94            }
 95            black_box(());
 96        }
 97    }
 98
 99    for params in [[10, 2, 2], [11, 2, 4], [12, 2, 8], [13, 2, 16], [14, 2, 32]] {
100        let id: BenchmarkId = BenchmarkId::from_parameter(format!("{}x({}x{})", 1 << params[0], params[1], params[2],));
101        let mut runner = runner::<B>(params);
102        group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
103    }
104
105    group.finish();
106}
107
108pub fn bench_vec_znx_big_add_small<B: Backend>(c: &mut Criterion, label: &str)
109where
110    Module<B>: VecZnxBigAddSmall<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
111{
112    let group_name: String = format!("vec_znx_big_add_small::{label}");
113
114    let mut group = c.benchmark_group(group_name);
115
116    fn runner<B: Backend>(params: [usize; 3]) -> impl FnMut()
117    where
118        Module<B>: VecZnxBigAddSmall<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
119    {
120        let n: usize = params[0];
121        let cols: usize = params[1];
122        let size: usize = params[2];
123
124        let module: Module<B> = Module::<B>::new(n as u64);
125
126        let mut source: Source = Source::new([0u8; 32]);
127
128        let mut a: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
129        let mut b: VecZnx<Vec<u8>> = VecZnx::alloc(n, cols, size);
130        let mut c: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
131
132        // Fill a with random i64
133        source.fill_bytes(a.data_mut());
134        source.fill_bytes(b.data_mut());
135        source.fill_bytes(c.data_mut());
136
137        move || {
138            for i in 0..cols {
139                module.vec_znx_big_add_small(&mut c, i, &a, i, &b, i);
140            }
141            black_box(());
142        }
143    }
144
145    for params in [[10, 2, 2], [11, 2, 4], [12, 2, 8], [13, 2, 16], [14, 2, 32]] {
146        let id: BenchmarkId = BenchmarkId::from_parameter(format!("{}x({}x{})", 1 << params[0], params[1], params[2],));
147        let mut runner = runner::<B>(params);
148        group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
149    }
150
151    group.finish();
152}
153
154pub fn bench_vec_znx_big_add_small_inplace<B: Backend>(c: &mut Criterion, label: &str)
155where
156    Module<B>: VecZnxBigAddSmallInplace<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
157{
158    let group_name: String = format!("vec_znx_big_add_small_inplace::{label}");
159
160    let mut group = c.benchmark_group(group_name);
161
162    fn runner<B: Backend>(params: [usize; 3]) -> impl FnMut()
163    where
164        Module<B>: VecZnxBigAddSmallInplace<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
165    {
166        let n: usize = params[0];
167        let cols: usize = params[1];
168        let size: usize = params[2];
169
170        let module: Module<B> = Module::<B>::new(n as u64);
171
172        let mut source: Source = Source::new([0u8; 32]);
173
174        let mut a: VecZnx<Vec<u8>> = VecZnx::alloc(n, cols, size);
175        let mut c: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
176
177        // Fill a with random i64
178        source.fill_bytes(a.data_mut());
179        source.fill_bytes(c.data_mut());
180
181        move || {
182            for i in 0..cols {
183                module.vec_znx_big_add_small_inplace(&mut c, i, &a, i);
184            }
185            black_box(());
186        }
187    }
188
189    for params in [[10, 2, 2], [11, 2, 4], [12, 2, 8], [13, 2, 16], [14, 2, 32]] {
190        let id: BenchmarkId = BenchmarkId::from_parameter(format!("{}x({}x{})", 1 << params[0], params[1], params[2],));
191        let mut runner = runner::<B>(params);
192        group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
193    }
194
195    group.finish();
196}
197
198pub fn bench_vec_znx_big_automorphism<B: Backend>(c: &mut Criterion, label: &str)
199where
200    Module<B>: VecZnxBigAutomorphism<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
201{
202    let group_name: String = format!("vec_znx_big_automorphism::{label}");
203
204    let mut group = c.benchmark_group(group_name);
205
206    fn runner<B: Backend>(params: [usize; 3]) -> impl FnMut()
207    where
208        Module<B>: VecZnxBigAutomorphism<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
209    {
210        let n: usize = params[0];
211        let cols: usize = params[1];
212        let size: usize = params[2];
213
214        let module: Module<B> = Module::<B>::new(n as u64);
215
216        let mut source: Source = Source::new([0u8; 32]);
217
218        let mut a: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
219        let mut res: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
220
221        // Fill a with random i64
222        source.fill_bytes(a.data_mut());
223        source.fill_bytes(res.data_mut());
224
225        move || {
226            for i in 0..cols {
227                module.vec_znx_big_automorphism(-7, &mut res, i, &a, i);
228            }
229            black_box(());
230        }
231    }
232
233    for params in [[10, 2, 2], [11, 2, 4], [12, 2, 8], [13, 2, 16], [14, 2, 32]] {
234        let id: BenchmarkId = BenchmarkId::from_parameter(format!("{}x({}x{})", 1 << params[0], params[1], params[2],));
235        let mut runner = runner::<B>(params);
236        group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
237    }
238
239    group.finish();
240}
241
242pub fn bench_vec_znx_automorphism_inplace<B: Backend>(c: &mut Criterion, label: &str)
243where
244    Module<B>: VecZnxBigAutomorphismInplace<B> + VecZnxBigAutomorphismInplaceTmpBytes + ModuleNew<B> + VecZnxBigAlloc<B>,
245    ScratchOwned<B>: ScratchOwnedAlloc<B> + ScratchOwnedBorrow<B>,
246{
247    let group_name: String = format!("vec_znx_automorphism_inplace::{label}");
248
249    let mut group = c.benchmark_group(group_name);
250
251    fn runner<B: Backend>(params: [usize; 3]) -> impl FnMut()
252    where
253        Module<B>: VecZnxBigAutomorphismInplace<B> + ModuleNew<B> + VecZnxBigAutomorphismInplaceTmpBytes + VecZnxBigAlloc<B>,
254        ScratchOwned<B>: ScratchOwnedAlloc<B> + ScratchOwnedBorrow<B>,
255    {
256        let n: usize = params[0];
257        let cols: usize = params[1];
258        let size: usize = params[2];
259
260        let module: Module<B> = Module::<B>::new(n as u64);
261
262        let mut source: Source = Source::new([0u8; 32]);
263
264        let mut res: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
265
266        let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(module.vec_znx_big_automorphism_inplace_tmp_bytes());
267
268        // Fill a with random i64
269        source.fill_bytes(res.data_mut());
270
271        move || {
272            for i in 0..cols {
273                module.vec_znx_big_automorphism_inplace(-7, &mut res, i, scratch.borrow());
274            }
275            black_box(());
276        }
277    }
278
279    for params in [[10, 2, 2], [11, 2, 4], [12, 2, 8], [13, 2, 16], [14, 2, 32]] {
280        let id: BenchmarkId = BenchmarkId::from_parameter(format!("{}x({}x{})", 1 << params[0], params[1], params[2],));
281        let mut runner = runner::<B>(params);
282        group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
283    }
284
285    group.finish();
286}
287
288pub fn bench_vec_znx_big_negate<B: Backend>(c: &mut Criterion, label: &str)
289where
290    Module<B>: VecZnxBigNegate<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
291{
292    let group_name: String = format!("vec_znx_big_negate::{label}");
293
294    let mut group = c.benchmark_group(group_name);
295
296    fn runner<B: Backend>(params: [usize; 3]) -> impl FnMut()
297    where
298        Module<B>: VecZnxBigNegate<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
299    {
300        let module: Module<B> = Module::<B>::new(1 << params[0]);
301
302        let cols: usize = params[1];
303        let size: usize = params[2];
304
305        let mut source: Source = Source::new([0u8; 32]);
306
307        let mut a: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
308        let mut b: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
309
310        // Fill a with random i64
311        source.fill_bytes(a.data_mut());
312        source.fill_bytes(b.data_mut());
313
314        move || {
315            for i in 0..cols {
316                module.vec_znx_big_negate(&mut b, i, &a, i);
317            }
318            black_box(());
319        }
320    }
321
322    for params in [[10, 2, 2], [11, 2, 4], [12, 2, 8], [13, 2, 16], [14, 2, 32]] {
323        let id: BenchmarkId = BenchmarkId::from_parameter(format!("{}x({}x{})", 1 << params[0], params[1], params[2],));
324        let mut runner = runner::<B>(params);
325        group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
326    }
327
328    group.finish();
329}
330
331pub fn bench_vec_znx_big_negate_inplace<B: Backend>(c: &mut Criterion, label: &str)
332where
333    Module<B>: VecZnxBigNegateInplace<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
334{
335    let group_name: String = format!("vec_znx_negate_big_inplace::{label}");
336
337    let mut group = c.benchmark_group(group_name);
338
339    fn runner<B: Backend>(params: [usize; 3]) -> impl FnMut()
340    where
341        Module<B>: VecZnxBigNegateInplace<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
342    {
343        let module: Module<B> = Module::<B>::new(1 << params[0]);
344
345        let cols: usize = params[1];
346        let size: usize = params[2];
347
348        let mut source: Source = Source::new([0u8; 32]);
349
350        let mut a: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
351
352        // Fill a with random i64
353        source.fill_bytes(a.data_mut());
354
355        move || {
356            for i in 0..cols {
357                module.vec_znx_big_negate_inplace(&mut a, i);
358            }
359            black_box(());
360        }
361    }
362
363    for params in [[10, 2, 2], [11, 2, 4], [12, 2, 8], [13, 2, 16], [14, 2, 32]] {
364        let id: BenchmarkId = BenchmarkId::from_parameter(format!("{}x({}x{})", 1 << params[0], params[1], params[2]));
365        let mut runner = runner::<B>(params);
366        group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
367    }
368
369    group.finish();
370}
371
372pub fn bench_vec_znx_normalize<B: Backend>(c: &mut Criterion, label: &str)
373where
374    Module<B>: VecZnxBigNormalize<B> + ModuleNew<B> + VecZnxBigNormalizeTmpBytes + VecZnxBigAlloc<B>,
375    ScratchOwned<B>: ScratchOwnedAlloc<B> + ScratchOwnedBorrow<B>,
376{
377    let group_name: String = format!("vec_znx_big_normalize::{label}");
378
379    let mut group = c.benchmark_group(group_name);
380
381    fn runner<B: Backend>(params: [usize; 3]) -> impl FnMut()
382    where
383        Module<B>: VecZnxBigNormalize<B> + ModuleNew<B> + VecZnxBigNormalizeTmpBytes + VecZnxBigAlloc<B>,
384        ScratchOwned<B>: ScratchOwnedAlloc<B> + ScratchOwnedBorrow<B>,
385    {
386        let n: usize = params[0];
387        let cols: usize = params[1];
388        let size: usize = params[2];
389
390        let module: Module<B> = Module::<B>::new(n as u64);
391
392        let base2k: usize = 50;
393
394        let mut source: Source = Source::new([0u8; 32]);
395
396        let mut a: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
397        let mut res: VecZnx<Vec<u8>> = VecZnx::alloc(module.n(), cols, size);
398
399        // Fill a with random i64
400        source.fill_bytes(a.data_mut());
401        source.fill_bytes(res.data_mut());
402
403        let mut scratch: ScratchOwned<B> = ScratchOwned::alloc(module.vec_znx_big_normalize_tmp_bytes());
404
405        move || {
406            for i in 0..cols {
407                module.vec_znx_big_normalize(&mut res, base2k, 0, i, &a, base2k, i, scratch.borrow());
408            }
409            black_box(());
410        }
411    }
412
413    for params in [[10, 2, 2], [11, 2, 4], [12, 2, 8], [13, 2, 16], [14, 2, 32]] {
414        let id: BenchmarkId = BenchmarkId::from_parameter(format!("{}x({}x{})", 1 << params[0], params[1], params[2],));
415        let mut runner = runner::<B>(params);
416        group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
417    }
418
419    group.finish();
420}
421
422pub fn bench_vec_znx_big_sub<B: Backend>(c: &mut Criterion, label: &str)
423where
424    Module<B>: VecZnxBigSub<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
425{
426    let group_name: String = format!("vec_znx_big_sub::{label}");
427
428    let mut group = c.benchmark_group(group_name);
429
430    fn runner<B: Backend>(params: [usize; 3]) -> impl FnMut()
431    where
432        Module<B>: VecZnxBigSub<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
433    {
434        let module: Module<B> = Module::<B>::new(1 << params[0]);
435
436        let cols: usize = params[1];
437        let size: usize = params[2];
438
439        let mut source: Source = Source::new([0u8; 32]);
440
441        let mut a: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
442        let mut b: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
443        let mut c: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
444
445        // Fill a with random bytes
446        source.fill_bytes(a.data_mut());
447        source.fill_bytes(b.data_mut());
448        source.fill_bytes(c.data_mut());
449
450        move || {
451            for i in 0..cols {
452                module.vec_znx_big_sub(&mut c, i, &a, i, &b, i);
453            }
454            black_box(());
455        }
456    }
457
458    for params in [[10, 2, 2], [11, 2, 4], [12, 2, 8], [13, 2, 16], [14, 2, 32]] {
459        let id: BenchmarkId = BenchmarkId::from_parameter(format!("{}x({}x{})", 1 << params[0], params[1], params[2],));
460        let mut runner = runner::<B>(params);
461        group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
462    }
463
464    group.finish();
465}
466
467pub fn bench_vec_znx_big_sub_inplace<B: Backend>(c: &mut Criterion, label: &str)
468where
469    Module<B>: VecZnxBigSubInplace<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
470{
471    let group_name: String = format!("vec_znx_big_sub_inplace::{label}");
472
473    let mut group = c.benchmark_group(group_name);
474
475    fn runner<B: Backend>(params: [usize; 3]) -> impl FnMut()
476    where
477        Module<B>: VecZnxBigSubInplace<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
478    {
479        let module: Module<B> = Module::<B>::new(1 << params[0]);
480
481        let cols: usize = params[1];
482        let size: usize = params[2];
483
484        let mut source: Source = Source::new([0u8; 32]);
485
486        let mut a: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
487        let mut c: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
488
489        // Fill a with random bytes
490        source.fill_bytes(a.data_mut());
491        source.fill_bytes(c.data_mut());
492
493        move || {
494            for i in 0..cols {
495                module.vec_znx_big_sub_inplace(&mut c, i, &a, i);
496            }
497            black_box(());
498        }
499    }
500
501    for params in [[10, 2, 2], [11, 2, 4], [12, 2, 8], [13, 2, 16], [14, 2, 32]] {
502        let id: BenchmarkId = BenchmarkId::from_parameter(format!("{}x({}x{})", 1 << params[0], params[1], params[2],));
503        let mut runner = runner::<B>(params);
504        group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
505    }
506
507    group.finish();
508}
509
510pub fn bench_vec_znx_big_sub_negate_inplace<B: Backend>(c: &mut Criterion, label: &str)
511where
512    Module<B>: VecZnxBigSubNegateInplace<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
513{
514    let group_name: String = format!("vec_znx_big_sub_inplace::{label}");
515
516    let mut group = c.benchmark_group(group_name);
517
518    fn runner<B: Backend>(params: [usize; 3]) -> impl FnMut()
519    where
520        Module<B>: VecZnxBigSubNegateInplace<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
521    {
522        let module: Module<B> = Module::<B>::new(1 << params[0]);
523
524        let cols: usize = params[1];
525        let size: usize = params[2];
526
527        let mut source: Source = Source::new([0u8; 32]);
528
529        let mut a: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
530        let mut c: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
531
532        // Fill a with random bytes
533        source.fill_bytes(a.data_mut());
534        source.fill_bytes(c.data_mut());
535
536        move || {
537            for i in 0..cols {
538                module.vec_znx_big_sub_negate_inplace(&mut c, i, &a, i);
539            }
540            black_box(());
541        }
542    }
543
544    for params in [[10, 2, 2], [11, 2, 4], [12, 2, 8], [13, 2, 16], [14, 2, 32]] {
545        let id: BenchmarkId = BenchmarkId::from_parameter(format!("{}x({}x{})", 1 << params[0], params[1], params[2],));
546        let mut runner = runner::<B>(params);
547        group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
548    }
549
550    group.finish();
551}
552
553pub fn bench_vec_znx_big_sub_small_a<B: Backend>(c: &mut Criterion, label: &str)
554where
555    Module<B>: VecZnxBigSubSmallA<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
556{
557    let group_name: String = format!("vec_znx_big_sub_small_a::{label}");
558
559    let mut group = c.benchmark_group(group_name);
560
561    fn runner<B: Backend>(params: [usize; 3]) -> impl FnMut()
562    where
563        Module<B>: VecZnxBigSubSmallA<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
564    {
565        let module: Module<B> = Module::<B>::new(1 << params[0]);
566
567        let cols: usize = params[1];
568        let size: usize = params[2];
569
570        let mut source: Source = Source::new([0u8; 32]);
571
572        let mut a: VecZnx<Vec<u8>> = VecZnx::alloc(module.n(), cols, size);
573        let mut b: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
574        let mut c: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
575
576        // Fill a with random bytes
577        source.fill_bytes(a.data_mut());
578        source.fill_bytes(b.data_mut());
579        source.fill_bytes(c.data_mut());
580
581        move || {
582            for i in 0..cols {
583                module.vec_znx_big_sub_small_a(&mut c, i, &a, i, &b, i);
584            }
585            black_box(());
586        }
587    }
588
589    for params in [[10, 2, 2], [11, 2, 4], [12, 2, 8], [13, 2, 16], [14, 2, 32]] {
590        let id: BenchmarkId = BenchmarkId::from_parameter(format!("{}x({}x{})", 1 << params[0], params[1], params[2],));
591        let mut runner = runner::<B>(params);
592        group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
593    }
594
595    group.finish();
596}
597
598pub fn bench_vec_znx_big_sub_small_b<B: Backend>(c: &mut Criterion, label: &str)
599where
600    Module<B>: VecZnxBigSubSmallB<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
601{
602    let group_name: String = format!("vec_znx_big_sub_small_b::{label}");
603
604    let mut group = c.benchmark_group(group_name);
605
606    fn runner<B: Backend>(params: [usize; 3]) -> impl FnMut()
607    where
608        Module<B>: VecZnxBigSubSmallB<B> + ModuleNew<B> + VecZnxBigAlloc<B>,
609    {
610        let module: Module<B> = Module::<B>::new(1 << params[0]);
611
612        let cols: usize = params[1];
613        let size: usize = params[2];
614
615        let mut source: Source = Source::new([0u8; 32]);
616
617        let mut a: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
618        let mut b: VecZnx<Vec<u8>> = VecZnx::alloc(module.n(), cols, size);
619        let mut c: VecZnxBig<Vec<u8>, B> = module.vec_znx_big_alloc(cols, size);
620
621        // Fill a with random bytes
622        source.fill_bytes(a.data_mut());
623        source.fill_bytes(b.data_mut());
624        source.fill_bytes(c.data_mut());
625
626        move || {
627            for i in 0..cols {
628                module.vec_znx_big_sub_small_b(&mut c, i, &a, i, &b, i);
629            }
630            black_box(());
631        }
632    }
633
634    for params in [[10, 2, 2], [11, 2, 4], [12, 2, 8], [13, 2, 16], [14, 2, 32]] {
635        let id: BenchmarkId = BenchmarkId::from_parameter(format!("{}x({}x{})", 1 << params[0], params[1], params[2],));
636        let mut runner = runner::<B>(params);
637        group.bench_with_input(id, &(), |b, _| b.iter(&mut runner));
638    }
639
640    group.finish();
641}