From 44a7ff8badf109cf18d3cac29122a8df09966761 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Thu, 18 Nov 2021 17:18:37 +0100 Subject: add more benchmarks for analyzers --- Cargo.toml | 4 ++++ benches/analyzers.rs | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 benches/analyzers.rs diff --git a/Cargo.toml b/Cargo.toml index f09dc1e..32a474b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,10 @@ default = [] name = "parsing_benchmark" harness = false +[[bench]] +name = "analyzers" +harness = false + [dev-dependencies] serde_json = "1.0" criterion = "0.3" diff --git a/benches/analyzers.rs b/benches/analyzers.rs new file mode 100644 index 0000000..61aee22 --- /dev/null +++ b/benches/analyzers.rs @@ -0,0 +1,61 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use evtclib::Compression; + +macro_rules! analyzer_benchmark { + ($fname:ident, $boss:expr, $log:expr) => { + fn $fname(c: &mut Criterion) { + let log = evtclib::process_file($log, Compression::Zip).unwrap(); + let analyzer = log.analyzer().unwrap(); + + c.bench_function(&format!("analyzers/{}/is_cm", $boss), |b| { + b.iter(|| { + black_box(analyzer.is_cm()); + }) + }); + + c.bench_function(&format!("analyzers/{}/outcome", $boss), |b| { + b.iter(|| { + black_box(analyzer.outcome()); + }) + }); + } + } +} + +macro_rules! benchmarks { + ($(($fname:ident, $boss:expr, $log:expr),)*) => { + $(analyzer_benchmark!($fname, $boss, $log);)* + + criterion_group! { + name = benches; + config = Criterion::default(); + targets = $($fname,)* + } + + criterion_main!(benches); + } +} + +benchmarks! { + (raid_generic, "generic-raid", "tests/logs/vg-20200421.zevtc"), + (raid_xera, "xera", "tests/logs/xera-20200415.zevtc"), + (raid_cairn, "cairn", "tests/logs/cairn-20200426.zevtc"), + (raid_mo, "mo", "tests/logs/mo-20200426.zevtc"), + (raid_samarog, "samarog", "tests/logs/samarog-20200426.zevtc"), + (raid_deimos, "deimos", "tests/logs/deimos-20200428.zevtc"), + (raid_sh, "sh", "tests/logs/desmina-20200425.zevtc"), + (raid_river, "river", "tests/logs/river-20210412.zevtc"), + (raid_dhuum, "dhuum", "tests/logs/dhuum-20200428.zevtc"), + (raid_ca, "ca", "tests/logs/ca-20200426.zevtc"), + (raid_largos, "largos", "tests/logs/largos-20200426.zevtc"), + (raid_qadim, "qadim", "tests/logs/qadim-20200427.zevtc"), + (raid_adina, "adina", "tests/logs/adina-20200427.zevtc"), + (raid_sabir, "sabir", "tests/logs/sabir-20200427.zevtc"), + (raid_qadimp, "qadimp", "tests/logs/qadimp-20200427.zevtc"), + + (fractal_generic, "generic-fractal", "tests/logs/ensolyss-20200427.zevtc"), + (fractal_ai, "ai", "tests/logs/ai-20200922.zevtc"), + (fractal_skorvald, "skorvald", "tests/logs/skorvald-20200920.zevtc"), + + (strike_generic, "generic-strike", "tests/logs/whisper-20200424.zevtc"), +} -- cgit v1.2.3 From e98584dba7de1e4306cf5176a7482cfe9afd2227 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Thu, 18 Nov 2021 18:20:55 +0100 Subject: add a Throughput to the analyzer benchmarks --- benches/analyzers.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/benches/analyzers.rs b/benches/analyzers.rs index 61aee22..2cbb87c 100644 --- a/benches/analyzers.rs +++ b/benches/analyzers.rs @@ -1,4 +1,4 @@ -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput}; use evtclib::Compression; macro_rules! analyzer_benchmark { @@ -7,17 +7,21 @@ macro_rules! analyzer_benchmark { let log = evtclib::process_file($log, Compression::Zip).unwrap(); let analyzer = log.analyzer().unwrap(); - c.bench_function(&format!("analyzers/{}/is_cm", $boss), |b| { + let mut group = c.benchmark_group(&format!("analyzers/{}", $boss)); + group.throughput(Throughput::Elements(1)); + + group.bench_function("is_cm", |b| { b.iter(|| { black_box(analyzer.is_cm()); }) }); - c.bench_function(&format!("analyzers/{}/outcome", $boss), |b| { + group.bench_function("outcome", |b| { b.iter(|| { black_box(analyzer.outcome()); }) }); + group.finish(); } } } -- cgit v1.2.3 From 903e3a393973e314e913e31172dc20afeeaedc17 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Thu, 18 Nov 2021 18:21:12 +0100 Subject: add html_reports feature to criterion --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 32a474b..4b22460 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ harness = false [dev-dependencies] serde_json = "1.0" -criterion = "0.3" +criterion = { version = "0.3", features = ["html_reports"] } [dependencies] num-traits = "0.2" -- cgit v1.2.3 From a327d9a85a0b51eb677d16e90b4fa15bb34bc00e Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Thu, 18 Nov 2021 18:33:35 +0100 Subject: clean up parsing benchmarks --- benches/parsing_benchmark.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/benches/parsing_benchmark.rs b/benches/parsing_benchmark.rs index 1e81e3c..4174cab 100644 --- a/benches/parsing_benchmark.rs +++ b/benches/parsing_benchmark.rs @@ -1,4 +1,4 @@ -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput}; use std::{fs, io, io::Read}; use zip::ZipArchive; @@ -11,7 +11,11 @@ const QADIM_LOG: &str = "tests/logs/qadim-20200427.zevtc"; /// (such as a buffered reader or a memory mapped file) so that the downstream application will /// receive the log fast. fn zipped_qadim_benchmark(c: &mut Criterion) { - c.bench_function("on-disk zipped Qadim", |b| { + let file_size = fs::metadata(QADIM_LOG).unwrap().len(); + let mut group = c.benchmark_group("parsing/qadim/zipped"); + + group.throughput(Throughput::Bytes(file_size)); + group.bench_function("disk", |b| { b.iter(|| evtclib::process_file(black_box(QADIM_LOG), evtclib::Compression::Zip).unwrap()) }); } @@ -24,8 +28,11 @@ fn zipped_qadim_benchmark(c: &mut Criterion) { /// have to de-compress logs at some point. fn zipped_qadim_ram_benchmark(c: &mut Criterion) { let log_data = &fs::read(QADIM_LOG).unwrap(); + let file_size = log_data.len(); + let mut group = c.benchmark_group("parsing/qadim/zipped"); - c.bench_function("in-memory zipped Qadim", |b| { + group.throughput(Throughput::Bytes(file_size as u64)); + group.bench_function("memory", |b| { b.iter(|| { evtclib::process_stream(io::Cursor::new(log_data), evtclib::Compression::Zip).unwrap() }) @@ -48,7 +55,10 @@ fn unzipped_qadim_benchmark(c: &mut Criterion) { .unwrap(); let log_data = &log_data; - c.bench_function("in-memory unzipped Qadim", |b| { + let mut group = c.benchmark_group("parsing/qadim/unzipped"); + + group.throughput(Throughput::Bytes(log_data.len() as u64)); + group.bench_function("memory", |b| { b.iter(|| { evtclib::process_stream(io::Cursor::new(log_data), evtclib::Compression::None).unwrap() }) @@ -66,7 +76,7 @@ fn process_qadim(c: &mut Criterion) { let file = io::BufReader::new(fs::File::open(QADIM_LOG).unwrap()); let raw_evtc = evtclib::raw::parse_zip(file).unwrap(); - c.bench_function("process Qadim", |b| { + c.bench_function("process/qadim", |b| { b.iter(|| evtclib::process(&raw_evtc).unwrap()) }); } -- cgit v1.2.3 From 24187066c136a01a9cb688e371ca748e36331e58 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Thu, 18 Nov 2021 18:34:16 +0100 Subject: formatting fix --- benches/analyzers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benches/analyzers.rs b/benches/analyzers.rs index 2cbb87c..ee25253 100644 --- a/benches/analyzers.rs +++ b/benches/analyzers.rs @@ -23,7 +23,7 @@ macro_rules! analyzer_benchmark { }); group.finish(); } - } + }; } macro_rules! benchmarks { -- cgit v1.2.3