-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add prepared queries and tiny benchmark
- Loading branch information
1 parent
3aff64e
commit 02d10fc
Showing
6 changed files
with
138 additions
and
54 deletions.
There are no files selected for viewing
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,49 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use tokio::runtime::Runtime; | ||
|
||
use pg_worm::{prelude::*, query::Prepared}; | ||
|
||
#[allow(dead_code)] | ||
#[derive(Model)] | ||
struct Book { | ||
#[column(primary_key, auto)] | ||
id: i64, | ||
title: String, | ||
author_id: i64, | ||
} | ||
|
||
#[allow(dead_code)] | ||
#[derive(Model)] | ||
struct Author { | ||
id: i64, | ||
title: String, | ||
} | ||
|
||
fn setup() { | ||
// Use the tokio runtime to complete the setup in an async block | ||
tokio::runtime::Runtime::new().unwrap().block_on(async { | ||
Connection::build("postgres://postgres:postgres@localhost:5432") | ||
.connect() | ||
.await | ||
.expect("benchmark setup: failed to connect"); | ||
|
||
force_create_table!(Book, Author) | ||
.await | ||
.expect("benchmark setup: failed to create tables"); | ||
}); | ||
} | ||
|
||
fn bench_main(criterion: &mut Criterion) { | ||
setup(); | ||
|
||
criterion.bench_function("all-books", |bench| { | ||
bench | ||
.to_async(Runtime::new().expect("failed to create runtime")) | ||
.iter(|| async { | ||
Book::select().await.expect("failed to query"); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, bench_main); | ||
criterion_main!(benches); |
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
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