@@ -7,7 +7,7 @@ use doublets::{
77} ;
88use tokio_postgres:: { Error , NoTls } ;
99
10- use linkspsql:: { Client , Cruds } ;
10+ use linkspsql:: { make_bench , Client , Cruds } ;
1111
1212async fn connect ( ) -> Result < Client , Error > {
1313 let ( client, connection) = tokio_postgres:: connect ( "" , NoTls ) . await . unwrap ( ) ;
@@ -23,43 +23,24 @@ async fn connect() -> Result<Client, Error> {
2323fn create_thousand_links_without_transaction ( c : & mut Criterion ) {
2424 let runtime = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
2525 let mut client = runtime. block_on ( connect ( ) ) . unwrap ( ) ;
26- c. bench_function ( "create_thousand_links_without_transaction" , |b| {
27- b. iter ( || {
28- runtime. block_on ( async {
29- for i in 1 ..=1_000 {
30- client. create ( & [ i; 2 ] ) . await . unwrap ( ) ;
31- }
32- } ) ;
33- } ) ;
34- runtime. block_on ( async {
35- for i in 1 ..=1_000 {
36- client. delete ( & [ i; 2 ] ) . await . unwrap ( ) ;
37- }
38- } ) ;
39- } ) ;
26+ make_bench ! (
27+ c,
28+ "create_thousand_links_without_transaction" ,
29+ client,
30+ runtime
31+ ) ;
4032}
4133
4234fn create_thousand_links_with_transaction ( c : & mut Criterion ) {
4335 let runtime = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
4436 let mut client = runtime. block_on ( connect ( ) ) . unwrap ( ) ;
45- c. bench_function ( "create_thousand_links_with_transaction" , |b| {
46- b. iter ( || {
47- runtime. block_on ( async {
48- let mut transaction = client. transaction ( ) . await . unwrap ( ) ;
49- for i in 1 ..=1_000 {
50- transaction. create ( & [ i; 2 ] ) . await . unwrap ( ) ;
51- }
52- transaction. commit ( ) . await . unwrap ( ) ;
53- } ) ;
54- } ) ;
55- runtime. block_on ( async {
56- let mut transaction = client. transaction ( ) . await . unwrap ( ) ;
57- for i in 1 ..=1_000 {
58- transaction. delete ( & [ i; 2 ] ) . await . unwrap ( ) ;
59- }
60- transaction. commit ( ) . await . unwrap ( ) ;
61- } ) ;
62- } ) ;
37+ make_bench ! (
38+ c,
39+ "create_thousand_links_with_transaction" ,
40+ client,
41+ runtime,
42+ transaction
43+ ) ;
6344}
6445
6546fn doublets_benchmark_ram ( c : & mut Criterion ) {
0 commit comments