mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-12-29 21:00:54 +00:00
Add diesel to select bench
This commit is contained in:
parent
200c87d9f0
commit
f79e901a3c
@ -40,6 +40,7 @@ tokio = { version = "=0.2.0-alpha.1" }
|
||||
[dev-dependencies]
|
||||
criterion = "0.2"
|
||||
rust_postgres = { version = "0.16.0-rc.2", package = "postgres" }
|
||||
diesel = { version = "1.4.2", features = [ "postgres" ] }
|
||||
|
||||
[[bench]]
|
||||
name = "select"
|
||||
|
||||
@ -21,6 +21,20 @@ fn rust_postgres_select(cl: &mut rust_postgres::Client) {
|
||||
}).collect();
|
||||
}
|
||||
|
||||
fn diesel_select(conn: &diesel::pg::PgConnection) {
|
||||
use diesel::query_dsl::RunQueryDsl;
|
||||
use diesel::QueryableByName;
|
||||
|
||||
#[derive(QueryableByName)]
|
||||
struct Contact {
|
||||
#[allow(unused)]
|
||||
#[sql_type = "diesel::sql_types::Text"]
|
||||
name: String,
|
||||
}
|
||||
|
||||
let _rows: Vec<Contact> = diesel::sql_query("SELECT name FROM contacts").load(conn).unwrap();
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("sqlx select", |b| {
|
||||
let rt = Runtime::new().unwrap();
|
||||
@ -40,6 +54,16 @@ fn criterion_benchmark(c: &mut Criterion) {
|
||||
rust_postgres_select(&mut cl);
|
||||
});
|
||||
});
|
||||
|
||||
c.bench_function("diesel select", |b| {
|
||||
use diesel::Connection;
|
||||
|
||||
let conn = diesel::pg::PgConnection::establish(DATABASE_URL).unwrap();
|
||||
|
||||
b.iter(|| {
|
||||
diesel_select(&conn);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user