From ce9ad58b76415c9555ff5d22b093a7f4575ede8b Mon Sep 17 00:00:00 2001 From: Patrice Billaut <57354406+pbillaut@users.noreply.github.com> Date: Sun, 15 Sep 2024 10:10:07 +0200 Subject: [PATCH] chore(benches): separate util mod --- benches/bench_main.rs | 28 ++----------------- benches/benchmarks/parsing.rs | 3 +- ...ransactions-10K.csv => activities_10K.csv} | 0 ...{transactions-1K.csv => activities_1K.csv} | 0 benches/util.rs | 24 ++++++++++++++++ 5 files changed, 28 insertions(+), 27 deletions(-) rename benches/data/{transactions-10K.csv => activities_10K.csv} (100%) rename benches/data/{transactions-1K.csv => activities_1K.csv} (100%) create mode 100644 benches/util.rs diff --git a/benches/bench_main.rs b/benches/bench_main.rs index 6a68cc8..60dfb14 100644 --- a/benches/bench_main.rs +++ b/benches/bench_main.rs @@ -1,36 +1,12 @@ use criterion::criterion_main; +mod util; mod benchmarks; -pub type ParseResult = Vec>; - -#[allow(unused_macros)] -macro_rules! open_file { - ($str_arg:expr) => {{ - let mut path = PathBuf::from(file!()); - path.pop(); - path.pop(); - path.push("data/"); - path.push($str_arg); - File::open(path).expect("Benchmark setup: unable to open file") - }}; -} -#[allow(unused_imports)] -pub(crate) use open_file; use payment_processor::account_activity::AccountActivity; use payment_processor::processors::csv::CsvProcessorResult; -#[allow(unused_macros)] -macro_rules! read_file { - ($str_arg:expr) => {{ - let mut file = open_file!($str_arg); - let mut buffer = Vec::new(); - file.read_to_end(&mut buffer).expect("Benchmark setup: unable to read file"); - buffer - }}; -} -#[allow(unused_imports)] -pub(crate) use read_file; +pub type ParseResult = Vec>; pub const SCENARIOS: [(&str, u64); 2] = [ ("activities_1K.csv", 1_000), diff --git a/benches/benchmarks/parsing.rs b/benches/benchmarks/parsing.rs index 1f62e0f..b121e82 100644 --- a/benches/benchmarks/parsing.rs +++ b/benches/benchmarks/parsing.rs @@ -1,4 +1,5 @@ -use crate::{open_file, read_file, ParseResult, SCENARIOS}; +use crate::util::{open_file, read_file}; +use crate::{ParseResult, SCENARIOS}; use criterion::{black_box, criterion_group, BenchmarkId, Criterion}; use payment_processor::processors::csv::reader::CsvReader; use std::fs::File; diff --git a/benches/data/transactions-10K.csv b/benches/data/activities_10K.csv similarity index 100% rename from benches/data/transactions-10K.csv rename to benches/data/activities_10K.csv diff --git a/benches/data/transactions-1K.csv b/benches/data/activities_1K.csv similarity index 100% rename from benches/data/transactions-1K.csv rename to benches/data/activities_1K.csv diff --git a/benches/util.rs b/benches/util.rs new file mode 100644 index 0000000..6936780 --- /dev/null +++ b/benches/util.rs @@ -0,0 +1,24 @@ +#![allow(unused_macros)] +#![allow(unused_imports)] + +macro_rules! open_file { + ($str_arg:expr) => {{ + let mut path = PathBuf::from(file!()); + path.pop(); + path.pop(); + path.push("data/"); + path.push($str_arg); + File::open(path).expect("Benchmark setup: unable to open file") + }}; +} +pub(crate) use open_file; + +macro_rules! read_file { + ($str_arg:expr) => {{ + let mut file = open_file!($str_arg); + let mut buffer = Vec::new(); + file.read_to_end(&mut buffer).expect("Benchmark setup: unable to read file"); + buffer + }}; +} +pub(crate) use read_file;