-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - Add benchmark for
create_transactions
- Loading branch information
Showing
3 changed files
with
63 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,57 @@ | ||
use std::sync::Arc; | ||
|
||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use mithril_common::{entities::CardanoTransaction, StdResult}; | ||
use mithril_persistence::sqlite::{ConnectionBuilder, ConnectionOptions}; | ||
use mithril_signer::database::repository::CardanoTransactionRepository; | ||
use sqlite::ConnectionThreadSafe; | ||
|
||
fn cardano_tx_db_connection() -> StdResult<ConnectionThreadSafe> { | ||
let connection = ConnectionBuilder::open_memory() | ||
.with_options(&[ConnectionOptions::ForceDisableForeignKeys]) | ||
.with_migrations(mithril_signer::database::cardano_transaction_migration::get_migrations()) | ||
.build()?; | ||
Ok(connection) | ||
} | ||
|
||
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_create_cardano_transactions(c: &mut Criterion) { | ||
const NB_CARDANO_TRANSACTIONS: usize = 100; | ||
let runtime = tokio::runtime::Runtime::new().unwrap(); | ||
|
||
let connection = Arc::new(cardano_tx_db_connection().unwrap()); | ||
let repository = CardanoTransactionRepository::new(connection); | ||
|
||
let mut group = c.benchmark_group("Create transactions"); | ||
group.bench_function("create_transactions 2", |bencher| { | ||
bencher.to_async(&runtime).iter(|| async { | ||
repository | ||
.create_transactions(generate_transactions(NB_CARDANO_TRANSACTIONS)) | ||
.await | ||
}); | ||
}); | ||
group.bench_function("create_transactions 2 bis", |bencher| { | ||
bencher.to_async(&runtime).iter(|| async { | ||
repository | ||
.create_transactions(generate_transactions(NB_CARDANO_TRANSACTIONS)) | ||
.await | ||
}); | ||
}); | ||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, bench_create_cardano_transactions); | ||
criterion_main!(benches); |