Skip to content

Commit ca5242c

Browse files
dlachaumesfauvel
authored andcommitted
Add bench store_transactions for in mithril-aggregator
1 parent ee9fbb2 commit ca5242c

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-aggregator/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ homepage = { workspace = true }
99
license = { workspace = true }
1010
repository = { workspace = true }
1111

12+
[[bench]]
13+
name = "cardano_transactions"
14+
harness = false
15+
1216
[dependencies]
1317
anyhow = "1.0.79"
1418
async-trait = "0.1.77"
@@ -50,6 +54,7 @@ zstd = { version = "0.13.0", features = ["zstdmt"] }
5054
tikv-jemallocator = { version = "0.5.4", optional = true }
5155

5256
[dev-dependencies]
57+
criterion = { version = "0.5.1", features = ["html_reports", "async_tokio"] }
5358
httpmock = "0.7.0"
5459
mithril-common = { path = "../mithril-common", features = [
5560
"allow_skip_signer_certification",
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use criterion::{criterion_group, criterion_main, Criterion};
2+
use sqlite::ConnectionThreadSafe;
3+
use std::sync::Arc;
4+
5+
use mithril_aggregator::{
6+
database::repository::CardanoTransactionRepository, services::TransactionStore,
7+
};
8+
use mithril_common::{entities::CardanoTransaction, test_utils::TempDir};
9+
use mithril_persistence::sqlite::ConnectionBuilder;
10+
11+
fn cardano_tx_db_connection() -> ConnectionThreadSafe {
12+
let db_path =
13+
TempDir::create("aggregator_benches", "bench_store_transactions").join("cardano_tx.db");
14+
15+
if db_path.exists() {
16+
std::fs::remove_file(db_path.clone()).unwrap();
17+
}
18+
19+
ConnectionBuilder::open_file(&db_path)
20+
.with_migrations(
21+
mithril_aggregator::database::cardano_transaction_migration::get_migrations(),
22+
)
23+
.build()
24+
.unwrap()
25+
}
26+
27+
fn generate_transactions(nb_transactions: usize) -> Vec<CardanoTransaction> {
28+
(0..nb_transactions)
29+
.map(|i| {
30+
CardanoTransaction::new(
31+
format!("tx_hash-{}", i),
32+
i as u64,
33+
i as u64 + 1,
34+
format!("block_hash-{}", i),
35+
i as u64 + 2,
36+
)
37+
})
38+
.collect()
39+
}
40+
41+
fn bench_store_transactions(c: &mut Criterion) {
42+
const NB_CARDANO_TRANSACTIONS: usize = 100000;
43+
let runtime = tokio::runtime::Runtime::new().unwrap();
44+
45+
let mut group = c.benchmark_group("Store transactions");
46+
group.bench_function("store_transactions", |bencher| {
47+
bencher.to_async(&runtime).iter(|| async {
48+
let connection = Arc::new(cardano_tx_db_connection());
49+
let repository = CardanoTransactionRepository::new(connection);
50+
repository
51+
.store_transactions(generate_transactions(NB_CARDANO_TRANSACTIONS))
52+
.await
53+
});
54+
});
55+
56+
group.finish();
57+
}
58+
59+
criterion_group!(benches, bench_store_transactions);
60+
criterion_main!(benches);

0 commit comments

Comments
 (0)