|
| 1 | +use criterion::{criterion_group, criterion_main, Criterion}; |
| 2 | +use dmap::formats::dmap::DmapRecord; |
| 3 | +use dmap::formats::fitacf::FitacfRecord; |
| 4 | +use dmap::formats::grid::GridRecord; |
| 5 | +use dmap::formats::iqdat::IqdatRecord; |
| 6 | +use dmap::formats::map::MapRecord; |
| 7 | +use dmap::formats::rawacf::RawacfRecord; |
| 8 | +use dmap::formats::snd::SndRecord; |
| 9 | +use dmap::record::Record; |
| 10 | +use dmap::types::DmapField; |
| 11 | +use indexmap::IndexMap; |
| 12 | +use paste::paste; |
| 13 | + |
| 14 | +fn criterion_benchmark(c: &mut Criterion) { |
| 15 | + c.bench_function("Read IQDAT", |b| b.iter(|| read_iqdat())); |
| 16 | + c.bench_function("Read RAWACF", |b| b.iter(|| read_rawacf())); |
| 17 | + c.bench_function("Read FITACF", |b| b.iter(|| read_fitacf())); |
| 18 | + c.bench_function("Read GRID", |b| b.iter(|| read_grid())); |
| 19 | + c.bench_function("Read SND", |b| b.iter(|| read_snd())); |
| 20 | + c.bench_function("Read MAP", |b| b.iter(|| read_map())); |
| 21 | + c.bench_function("Read DMAP", |b| b.iter(|| read_dmap())); |
| 22 | + |
| 23 | + c.bench_function("Read bzipped IQDAT", |b| b.iter(|| read_iqdat_bz2())); |
| 24 | + c.bench_function("Read bzipped RAWACF", |b| b.iter(|| read_rawacf_bz2())); |
| 25 | + c.bench_function("Read bzipped FITACF", |b| b.iter(|| read_fitacf_bz2())); |
| 26 | + c.bench_function("Read bzipped GRID", |b| b.iter(|| read_grid_bz2())); |
| 27 | + c.bench_function("Read bzipped SND", |b| b.iter(|| read_snd_bz2())); |
| 28 | + c.bench_function("Read bzipped MAP", |b| b.iter(|| read_map_bz2())); |
| 29 | + c.bench_function("Read bzipped DMAP", |b| b.iter(|| read_dmap_bz2())); |
| 30 | + |
| 31 | + c.bench_function("Read IQDAT metadata", |b| b.iter(|| read_iqdat_metadata())); |
| 32 | + c.bench_function("Read RAWACF metadata", |b| b.iter(|| read_rawacf_metadata())); |
| 33 | + c.bench_function("Read FITACF metadata", |b| b.iter(|| read_fitacf_metadata())); |
| 34 | + c.bench_function("Read GRID metadata", |b| b.iter(|| read_grid_metadata())); |
| 35 | + c.bench_function("Read SND metadata", |b| b.iter(|| read_snd_metadata())); |
| 36 | + c.bench_function("Read MAP metadata", |b| b.iter(|| read_map_metadata())); |
| 37 | + c.bench_function("Read DMAP metadata", |b| b.iter(|| read_dmap_metadata())); |
| 38 | + |
| 39 | + // let records = read_iqdat(); |
| 40 | + // c.bench_with_input( |
| 41 | + // BenchmarkId::new("Write IQDAT", "IQDAT Records"), |
| 42 | + // &records, |
| 43 | + // |b, s| b.iter(|| write_iqdat(s)), |
| 44 | + // ); |
| 45 | +} |
| 46 | + |
| 47 | +/// Generates benchmark functions for a given DMAP record type. |
| 48 | +macro_rules! read_type { |
| 49 | + ($type:ident, $name:literal) => { |
| 50 | + paste! { |
| 51 | + fn [< read_ $type >]() -> Vec<[< $type:camel Record >]> { |
| 52 | + [< $type:camel Record >]::read_file(format!("tests/test_files/test.{}", $name)).unwrap() |
| 53 | + } |
| 54 | + |
| 55 | + fn [< read_ $type _bz2 >]() -> Vec<[< $type:camel Record >]> { |
| 56 | + [< $type:camel Record >]::read_file(format!("tests/test_files/test.{}.bz2", $name)).unwrap() |
| 57 | + } |
| 58 | + |
| 59 | + fn [< read_ $type _metadata >]() -> Vec<IndexMap<String, DmapField>> { |
| 60 | + [< $type:camel Record >]::read_file_metadata(format!("tests/test_files/test.{}", $name)).unwrap() |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +read_type!(iqdat, "iqdat"); |
| 67 | +read_type!(rawacf, "rawacf"); |
| 68 | +read_type!(fitacf, "fitacf"); |
| 69 | +read_type!(grid, "grid"); |
| 70 | +read_type!(map, "map"); |
| 71 | +read_type!(snd, "snd"); |
| 72 | +read_type!(dmap, "rawacf"); |
| 73 | + |
| 74 | +criterion_group! { |
| 75 | + name = benches; |
| 76 | + config = Criterion::default(); |
| 77 | + targets = criterion_benchmark |
| 78 | +} |
| 79 | +criterion_main!(benches); |
0 commit comments