-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bench
store_transactions
for in mithril-aggregator
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,60 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use sqlite::ConnectionThreadSafe; | ||
use std::sync::Arc; | ||
|
||
use mithril_aggregator::{ | ||
database::repository::CardanoTransactionRepository, services::TransactionStore, | ||
}; | ||
use mithril_common::{entities::CardanoTransaction, test_utils::TempDir}; | ||
use mithril_persistence::sqlite::ConnectionBuilder; | ||
|
||
fn cardano_tx_db_connection() -> ConnectionThreadSafe { | ||
let db_path = | ||
TempDir::create("aggregator_benches", "bench_store_transactions").join("cardano_tx.db"); | ||
|
||
if db_path.exists() { | ||
std::fs::remove_file(db_path.clone()).unwrap(); | ||
} | ||
|
||
ConnectionBuilder::open_file(&db_path) | ||
.with_migrations( | ||
mithril_aggregator::database::cardano_transaction_migration::get_migrations(), | ||
) | ||
.build() | ||
.unwrap() | ||
} | ||
|
||
fn generate_transactions(nb_transactions: usize) -> Vec<CardanoTransaction> { | ||
(0..nb_transactions) | ||
.map(|i| { | ||
CardanoTransaction::new( | ||
format!("tx_hash-{}", i), | ||
i as u64, | ||
i as u64 + 1, | ||
format!("block_hash-{}", i), | ||
i as u64 + 2, | ||
) | ||
}) | ||
.collect() | ||
} | ||
|
||
fn bench_store_transactions(c: &mut Criterion) { | ||
const NB_CARDANO_TRANSACTIONS: usize = 100000; | ||
let runtime = tokio::runtime::Runtime::new().unwrap(); | ||
|
||
let mut group = c.benchmark_group("Store transactions"); | ||
group.bench_function("store_transactions", |bencher| { | ||
bencher.to_async(&runtime).iter(|| async { | ||
let connection = Arc::new(cardano_tx_db_connection()); | ||
let repository = CardanoTransactionRepository::new(connection); | ||
repository | ||
.store_transactions(generate_transactions(NB_CARDANO_TRANSACTIONS)) | ||
.await | ||
}); | ||
}); | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, bench_store_transactions); | ||
criterion_main!(benches); |