From ab847f76c4b2066b1cca329e751fc6f6ebd9a91a Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Tue, 20 Aug 2019 16:29:00 -0700 Subject: [PATCH] Remove select benchmark, too variable --- Cargo.toml | 6 --- benches/select.rs | 106 ---------------------------------------------- 2 files changed, 112 deletions(-) delete mode 100644 benches/select.rs diff --git a/Cargo.toml b/Cargo.toml index cd4734ec..d176488d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,12 +39,6 @@ tokio = { version = "=0.2.0-alpha.2" } [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" -harness = false [[bench]] name = "postgres_protocol_decode" diff --git a/benches/select.rs b/benches/select.rs deleted file mode 100644 index cef5ab8b..00000000 --- a/benches/select.rs +++ /dev/null @@ -1,106 +0,0 @@ -#![feature(async_await)] - -#[macro_use] -extern crate criterion; - -#[macro_use] -extern crate diesel; - -use criterion::Criterion; -use futures::stream::TryStreamExt; -use tokio::runtime::Runtime; - -use sqlx::Query as _; - -const DATABASE_URL: &str = "postgres://postgres@127.0.0.1:5432/sqlx__dev"; - -async fn sqlx_select(conn: &sqlx::Connection) { - let _rows: Vec = sqlx::query::("SELECT name FROM contacts") - .fetch(conn) - .try_collect() - .await - .unwrap(); -} - -fn rust_postgres_select(cl: &mut rust_postgres::Client) { - let _rows: Vec = cl - .query("SELECT name FROM contacts", &[]) - .unwrap() - .into_iter() - .map(|row| row.get(0)) - .collect(); -} - -fn diesel_select(conn: &diesel::pg::PgConnection) { - use diesel::query_dsl::RunQueryDsl; - - #[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 diesel_dsl_select(conn: &diesel::pg::PgConnection) { - use diesel::prelude::*; - - table! { - contacts { - id -> BigInt, - name -> Text, - } - } - - let _rows: Vec = contacts::table.select(contacts::name).load(conn).unwrap(); -} - -fn criterion_benchmark(c: &mut Criterion) { - c.bench_function("sqlx select", |b| { - let rt = Runtime::new().unwrap(); - let conn = rt.block_on(async { - sqlx::Connection::::establish(DATABASE_URL) - .await - .unwrap() - }); - - b.iter(|| { - rt.block_on(sqlx_select(&conn)); - }); - }); - - c.bench_function("rust-postgres select", |b| { - let mut cl = rust_postgres::Client::connect(DATABASE_URL, rust_postgres::NoTls).unwrap(); - - b.iter(|| { - 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); - }); - }); - - c.bench_function("diesel dsl select", |b| { - use diesel::Connection; - - let conn = diesel::pg::PgConnection::establish(DATABASE_URL).unwrap(); - - b.iter(|| { - diesel_dsl_select(&conn); - }); - }); -} - -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches);