|
| 1 | +use criterion::{black_box, criterion_group, criterion_main, Criterion}; |
| 2 | +use llvm_profparser::*; |
| 3 | +use std::fs; |
| 4 | + |
| 5 | +// This benchmark is a bit faffy as first you need to generate the binaries and profraws and pop |
| 6 | +// them in the appropriate folder structure. After that it will work as expected |
| 7 | + |
| 8 | +pub fn coverage_mapping(c: &mut Criterion) { |
| 9 | + let files = fs::read_dir("./benches/data/mapping/profraws") |
| 10 | + .unwrap() |
| 11 | + .map(|x| x.unwrap().path()) |
| 12 | + .collect::<Vec<_>>(); |
| 13 | + |
| 14 | + let profile = merge_profiles(&files).unwrap(); |
| 15 | + |
| 16 | + let binaries = fs::read_dir("./benches/data/mapping/binaries") |
| 17 | + .unwrap() |
| 18 | + .map(|x| x.unwrap().path()) |
| 19 | + .collect::<Vec<_>>(); |
| 20 | + |
| 21 | + c.bench_function("coverage mapping", |b| { |
| 22 | + b.iter(|| { |
| 23 | + let _a = CoverageMapping::new(black_box(&binaries), black_box(&profile), true).unwrap(); |
| 24 | + }) |
| 25 | + }); |
| 26 | +} |
| 27 | + |
| 28 | +pub fn report_generation(c: &mut Criterion) { |
| 29 | + let files = fs::read_dir("./benches/data/mapping/profraws") |
| 30 | + .unwrap() |
| 31 | + .map(|x| x.unwrap().path()) |
| 32 | + .collect::<Vec<_>>(); |
| 33 | + |
| 34 | + let profile = merge_profiles(&files).unwrap(); |
| 35 | + |
| 36 | + let binaries = fs::read_dir("./benches/data/mapping/binaries") |
| 37 | + .unwrap() |
| 38 | + .map(|x| x.unwrap().path()) |
| 39 | + .collect::<Vec<_>>(); |
| 40 | + |
| 41 | + let mapping = CoverageMapping::new(&binaries, &profile, true).unwrap(); |
| 42 | + |
| 43 | + c.bench_function("report generation", |b| { |
| 44 | + b.iter(|| { |
| 45 | + let _a = mapping.generate_report(); |
| 46 | + }) |
| 47 | + }); |
| 48 | +} |
| 49 | + |
| 50 | +pub fn subreport_generation(c: &mut Criterion) { |
| 51 | + let files = fs::read_dir("./benches/data/mapping/profraws") |
| 52 | + .unwrap() |
| 53 | + .map(|x| x.unwrap().path()) |
| 54 | + .collect::<Vec<_>>(); |
| 55 | + |
| 56 | + let profile = merge_profiles(&files).unwrap(); |
| 57 | + |
| 58 | + let binaries = fs::read_dir("./benches/data/mapping/binaries") |
| 59 | + .unwrap() |
| 60 | + .map(|x| x.unwrap().path()) |
| 61 | + .collect::<Vec<_>>(); |
| 62 | + |
| 63 | + let mapping = CoverageMapping::new(&binaries, &profile, true).unwrap(); |
| 64 | + |
| 65 | + c.bench_function("subreport generation", |b| { |
| 66 | + b.iter(|| { |
| 67 | + let _a = mapping.generate_subreport(|paths| { |
| 68 | + paths |
| 69 | + .iter() |
| 70 | + .any(|path| path.starts_with("/home/daniel/personal/tarpaulin/src")) |
| 71 | + }); |
| 72 | + }) |
| 73 | + }); |
| 74 | +} |
| 75 | + |
| 76 | +criterion_group!( |
| 77 | + benches, |
| 78 | + coverage_mapping, |
| 79 | + report_generation, |
| 80 | + subreport_generation |
| 81 | +); |
| 82 | + |
| 83 | +criterion_main!(benches); |
0 commit comments