Skip to content

Commit

Permalink
chore(benches): separate util mod
Browse files Browse the repository at this point in the history
  • Loading branch information
pbillaut authored Sep 15, 2024
1 parent c6c29f5 commit ce9ad58
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 deletions.
28 changes: 2 additions & 26 deletions benches/bench_main.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
use criterion::criterion_main;

mod util;
mod benchmarks;

pub type ParseResult = Vec<CsvProcessorResult<AccountActivity>>;

#[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<CsvProcessorResult<AccountActivity>>;

pub const SCENARIOS: [(&str, u64); 2] = [
("activities_1K.csv", 1_000),
Expand Down
3 changes: 2 additions & 1 deletion benches/benchmarks/parsing.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions benches/util.rs
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit ce9ad58

Please sign in to comment.