Skip to content

Commit 39f373e

Browse files
authored
Use macro to benchmark
1 parent e444639 commit 39f373e

File tree

6 files changed

+247
-225
lines changed

6 files changed

+247
-225
lines changed

rust/benches/bench.rs

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use doublets::{
77
};
88
use tokio_postgres::{Error, NoTls};
99

10-
use linkspsql::{Client, Cruds};
10+
use linkspsql::{make_bench, Client, Cruds};
1111

1212
async 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> {
2323
fn 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

4234
fn 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

6546
fn doublets_benchmark_ram(c: &mut Criterion) {

rust/src/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ impl Client {
2121
#[async_trait]
2222
impl Cruds<'_, postgres::Client> for Client {
2323
#[inline]
24-
fn zero(&mut self) -> &mut u64 {
24+
fn index(&mut self) -> &mut u64 {
2525
&mut self.0
2626
}
2727

2828
#[inline]
29-
fn one(&mut self) -> &postgres::Client {
29+
fn executor(&mut self) -> &postgres::Client {
3030
&self.1
3131
}
3232
}

0 commit comments

Comments
 (0)