@@ -19,6 +19,17 @@ fn cardano_tx_db_connection() -> StdResult<ConnectionThreadSafe> {
19
19
Ok ( connection)
20
20
}
21
21
22
+ async fn store_transactions_with_sqlite_transaction (
23
+ repository : CardanoTransactionRepository ,
24
+ transactions : Vec < CardanoTransaction > ,
25
+ ) -> StdResult < ( ) > {
26
+ repository. connection . execute ( "BEGIN TRANSACTION;" ) ?;
27
+ repository. store_transactions ( transactions) . await ?;
28
+ repository. connection . execute ( "END TRANSACTION;" ) ?;
29
+
30
+ Ok ( ( ) )
31
+ }
32
+
22
33
fn generate_transactions ( nb_transactions : usize ) -> Vec < CardanoTransaction > {
23
34
( 0 ..nb_transactions)
24
35
. map ( |i| {
@@ -34,7 +45,7 @@ fn generate_transactions(nb_transactions: usize) -> Vec<CardanoTransaction> {
34
45
}
35
46
36
47
fn bench_store_transactions_transactions ( c : & mut Criterion ) {
37
- const NB_CARDANO_TRANSACTIONS : usize = 100000 ;
48
+ const NB_CARDANO_TRANSACTIONS : usize = 10000 ;
38
49
let runtime = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
39
50
40
51
let mut group = c. benchmark_group ( "Create transactions" ) ;
@@ -49,6 +60,18 @@ fn bench_store_transactions_transactions(c: &mut Criterion) {
49
60
} ) ;
50
61
} ) ;
51
62
63
+ group. bench_function ( "store_transactions_with_sqlite_transaction" , |bencher| {
64
+ bencher. to_async ( & runtime) . iter ( || async {
65
+ let connection = Arc :: new ( cardano_tx_db_connection ( ) . unwrap ( ) ) ;
66
+ let repository = CardanoTransactionRepository :: new ( connection) ;
67
+ store_transactions_with_sqlite_transaction (
68
+ repository,
69
+ generate_transactions ( NB_CARDANO_TRANSACTIONS ) ,
70
+ )
71
+ . await
72
+ } ) ;
73
+ } ) ;
74
+
52
75
for chunks_size in [ 10 , 50 , 100 , 200 ] {
53
76
group. bench_function (
54
77
format ! ( "store_transactions_with_chunks_size = {}" , chunks_size) ,
0 commit comments