|
| 1 | +use criterion::{black_box, criterion_group, criterion_main, Criterion}; |
| 2 | +use dev_utils::{config, utils}; |
| 3 | +use downsample_rs::fpcs as fpcs_mod; |
| 4 | + |
| 5 | +fn fpcs_f32_random_array_long(c: &mut Criterion) { |
| 6 | + let n = config::ARRAY_LENGTH_LONG; |
| 7 | + let y = utils::get_random_array::<f32>(n, f32::MIN, f32::MAX); |
| 8 | + let x = (0..n).map(|i| i as i32).collect::<Vec<i32>>(); |
| 9 | + |
| 10 | + // Non parallel |
| 11 | + // --- without x |
| 12 | + c.bench_function("fpcs_vanilla_f32", |b| { |
| 13 | + b.iter(|| fpcs_mod::vanilla_fpcs_without_x(black_box(y.as_slice()), black_box(2_000))) |
| 14 | + }); |
| 15 | + c.bench_function("fpcs_mm_f32", |b| { |
| 16 | + b.iter(|| fpcs_mod::fpcs_without_x(black_box(y.as_slice()), black_box(2_000))) |
| 17 | + }); |
| 18 | + // --- with x |
| 19 | + c.bench_function("fpcs_mm_f32_x", |b| { |
| 20 | + b.iter(|| { |
| 21 | + fpcs_mod::fpcs_with_x( |
| 22 | + black_box(x.as_slice()), |
| 23 | + black_box(y.as_slice()), |
| 24 | + black_box(2_000), |
| 25 | + ) |
| 26 | + }) |
| 27 | + }); |
| 28 | + |
| 29 | + // Parallel |
| 30 | + // --- without x |
| 31 | + c.bench_function("fpcs_mm_f32_par", |b| { |
| 32 | + b.iter(|| fpcs_mod::fpcs_without_x_parallel(black_box(y.as_slice()), black_box(2_000))) |
| 33 | + }); |
| 34 | + // --- with x |
| 35 | + c.bench_function("fpcs_mm_f32_x_par", |b| { |
| 36 | + b.iter(|| { |
| 37 | + fpcs_mod::fpcs_with_x_parallel( |
| 38 | + black_box(x.as_slice()), |
| 39 | + black_box(y.as_slice()), |
| 40 | + black_box(2_000), |
| 41 | + ) |
| 42 | + }) |
| 43 | + }); |
| 44 | +} |
| 45 | + |
| 46 | +fn fpcs_f32_random_array_50m(c: &mut Criterion) { |
| 47 | + let n = 50_000_000; |
| 48 | + let y = utils::get_random_array::<f32>(n, f32::MIN, f32::MAX); |
| 49 | + let x = (0..n).map(|i| i as i32).collect::<Vec<i32>>(); |
| 50 | + |
| 51 | + // Non parallel |
| 52 | + // --- without x |
| 53 | + c.bench_function("fpcs_vanilla_50M_f32", |b| { |
| 54 | + b.iter(|| fpcs_mod::vanilla_fpcs_without_x(black_box(y.as_slice()), black_box(2_000))) |
| 55 | + }); |
| 56 | + c.bench_function("fpcs_mm_50M_f32", |b| { |
| 57 | + b.iter(|| fpcs_mod::fpcs_without_x(black_box(y.as_slice()), black_box(2_000))) |
| 58 | + }); |
| 59 | + // --- with x |
| 60 | + c.bench_function("fpcs_mm_50M_f32_x", |b| { |
| 61 | + b.iter(|| { |
| 62 | + fpcs_mod::fpcs_with_x( |
| 63 | + black_box(x.as_slice()), |
| 64 | + black_box(y.as_slice()), |
| 65 | + black_box(2_000), |
| 66 | + ) |
| 67 | + }) |
| 68 | + }); |
| 69 | + // Parallel |
| 70 | + // --- without x |
| 71 | + c.bench_function("fpcs_mm_50M_f32_par", |b| { |
| 72 | + b.iter(|| fpcs_mod::fpcs_without_x_parallel(black_box(y.as_slice()), black_box(2_000))) |
| 73 | + }); |
| 74 | + // --- with x |
| 75 | + c.bench_function("fpcs_mm_50M_f32_x_par", |b| { |
| 76 | + b.iter(|| { |
| 77 | + fpcs_mod::fpcs_with_x_parallel( |
| 78 | + black_box(x.as_slice()), |
| 79 | + black_box(y.as_slice()), |
| 80 | + black_box(2_000), |
| 81 | + ) |
| 82 | + }) |
| 83 | + }); |
| 84 | +} |
| 85 | + |
| 86 | +criterion_group!( |
| 87 | + benches, |
| 88 | + // |
| 89 | + fpcs_f32_random_array_long, |
| 90 | + fpcs_f32_random_array_50m, |
| 91 | +); |
| 92 | +criterion_main!(benches); |
0 commit comments