diff --git a/Cargo.toml b/Cargo.toml index c36b0f4a..eac49c6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/benches/select.rs b/benches/select.rs index 11ed8c6f..86a3691c 100644 --- a/benches/select.rs +++ b/benches/select.rs @@ -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 = 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);