-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
143,117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use criterion::criterion_main; | ||
|
||
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 const SCENARIOS: [(&str, u64); 2] = [ | ||
("activities_1K.csv", 1_000), | ||
("activities_10K.csv", 10_000), | ||
]; | ||
|
||
criterion_main!( | ||
benchmarks::parsing::benches, | ||
benchmarks::processing::benches, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod parsing; | ||
pub mod processing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::{open_file, read_file, ParseResult, SCENARIOS}; | ||
use criterion::{black_box, criterion_group, BenchmarkId, Criterion}; | ||
use payment_processor::processors::csv::reader::CsvReader; | ||
use std::fs::File; | ||
use std::io::Read; | ||
use std::path::PathBuf; | ||
|
||
fn bench_parsing(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("CsvReader::iter"); | ||
for (filename, num_elements) in SCENARIOS { | ||
let buffer = read_file!(filename); | ||
group.throughput(criterion::Throughput::Elements(num_elements)); | ||
group.bench_with_input( | ||
BenchmarkId::from_parameter(num_elements), &buffer, | ||
|b, buffer| b.iter(|| { | ||
let mut reader = CsvReader::try_new(black_box(buffer.as_slice())) | ||
.expect("Benchmark: unable to create csv reader"); | ||
reader.iter().collect::<ParseResult>() | ||
}), | ||
); | ||
} | ||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, bench_parsing); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::ParseResult; | ||
use criterion::{black_box, criterion_group, BatchSize, Criterion}; | ||
use payment_processor::account_activity::AccountActivity; | ||
use payment_processor::processor::Processor; | ||
use payment_processor::processors::csv::CsvProcessor; | ||
use payment_processor::transaction::TransactionID; | ||
use payment_processor::ClientID; | ||
|
||
fn bench_process_transactions(c: &mut Criterion) { | ||
let client_id_1 = ClientID(1); | ||
let client_id_2 = ClientID(2); | ||
let transactions = vec![ | ||
AccountActivity::deposit(TransactionID(1), client_id_1, 100.0), | ||
AccountActivity::dispute(TransactionID(1), client_id_1), | ||
AccountActivity::deposit(TransactionID(2), client_id_1, 100.0), | ||
AccountActivity::withdrawal(TransactionID(3), client_id_1, 50.0), | ||
AccountActivity::resolve(TransactionID(1), client_id_1), | ||
AccountActivity::dispute(TransactionID(2), client_id_1), | ||
AccountActivity::chargeback(TransactionID(2), client_id_1), | ||
AccountActivity::withdrawal(TransactionID(4), client_id_1, 100.0), | ||
AccountActivity::deposit(TransactionID(1), client_id_2, 100.0), | ||
AccountActivity::dispute(TransactionID(1), client_id_2), | ||
AccountActivity::deposit(TransactionID(2), client_id_2, 100.0), | ||
AccountActivity::withdrawal(TransactionID(3), client_id_2, 50.0), | ||
AccountActivity::resolve(TransactionID(1), client_id_2), | ||
AccountActivity::dispute(TransactionID(2), client_id_2), | ||
AccountActivity::chargeback(TransactionID(2), client_id_2), | ||
AccountActivity::withdrawal(TransactionID(4), client_id_2, 100.0), | ||
]; | ||
let processor = CsvProcessor::new(); | ||
|
||
c.bench_function("CsvProcessor::process_account_activity [dispute process]", move |b| { | ||
b.iter_batched( | ||
|| transactions.clone().into_iter().map(Ok).collect::<ParseResult>(), | ||
|transactions| processor.process_account_activity(black_box(transactions.into_iter())), | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, bench_process_transactions); |
Oops, something went wrong.