Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Benchmarks] Remove some duplication #3893

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions diesel_bench/benches/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#[cfg(all(feature = "sqlx", feature = "sqlite"))]
type Id = i64;
#[cfg(not(all(feature = "sqlx", feature = "sqlite")))]
type Id = i32;

diesel::table! {
comments {
id -> Integer,
post_id -> Integer,
text -> Text,
}
}

diesel::table! {
posts {
id -> Integer,
user_id -> Integer,
title -> Text,
body -> Nullable<Text>,
}
}

diesel::table! {
users {
id -> Integer,
name -> Text,
hair_color -> Nullable<Text>,
}
}

diesel::joinable!(comments -> posts (post_id));
diesel::joinable!(posts -> users (user_id));
diesel::allow_tables_to_appear_in_same_query!(users, posts, comments);

#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(
Clone,
Debug,
Eq,
PartialEq,
diesel::Associations,
diesel::Identifiable,
diesel::Queryable,
)]
#[diesel(belongs_to(Post))]
pub struct Comment {
pub id: Id,
pub post_id: Id,
pub text: String,
}

#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(
Clone,
Debug,
Eq,
PartialEq,
diesel::Associations,
diesel::Identifiable,
diesel::Queryable,
diesel::QueryableByName,
)]
#[diesel(belongs_to(User))]
#[diesel(table_name = posts)]
pub struct Post {
pub id: Id,
pub user_id: Id,
pub title: String,
pub body: Option<String>,
}

#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(
Clone,
Debug,
Eq,
PartialEq,
diesel::AsChangeset,
diesel::Identifiable,
diesel::Insertable,
diesel::Queryable,
diesel::QueryableByName,
)]
#[diesel(table_name = users)]
pub struct User {
pub id: Id,
pub name: String,
pub hair_color: Option<String>,
}
68 changes: 5 additions & 63 deletions diesel_bench/benches/diesel_async_benches.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#[path = "common.rs"]
mod common;

use common::*;
use super::Bencher;
use diesel::insert_into;
use diesel::prelude::{
allow_tables_to_appear_in_same_query, joinable, table, AsChangeset, Associations,
BelongingToDsl, ExpressionMethods, GroupedBy, Identifiable, Insertable, QueryDsl, Queryable,
QueryableByName,
};
use diesel::*;
use diesel_async::AsyncConnection;
use diesel_async::RunQueryDsl;
use tokio::runtime::Runtime;
Expand All @@ -15,45 +14,6 @@ type TestConnection = diesel_async::AsyncPgConnection;
#[cfg(feature = "mysql")]
type TestConnection = diesel_async::AsyncMysqlConnection;

table! {
users {
id -> Integer,
name -> Text,
hair_color -> Nullable<Text>,
}
}

table! {
posts {
id -> Integer,
user_id -> Integer,
title -> Text,
body -> Nullable<Text>,
}
}

table! {
comments {
id -> Integer,
post_id -> Integer,
text -> Text,
}
}

joinable!(comments -> posts (post_id));
joinable!(posts -> users (user_id));
allow_tables_to_appear_in_same_query!(users, posts, comments);

#[derive(
PartialEq, Eq, Debug, Clone, Queryable, Identifiable, Insertable, AsChangeset, QueryableByName,
)]
#[diesel(table_name = users)]
pub struct User {
pub id: i32,
pub name: String,
pub hair_color: Option<String>,
}

#[derive(Debug, PartialEq, Eq, Queryable, Clone, Insertable, AsChangeset)]
#[diesel(table_name = users)]
#[diesel(treat_none_as_default_value = false)]
Expand All @@ -71,16 +31,6 @@ impl NewUser {
}
}

#[derive(PartialEq, Eq, Debug, Clone, Queryable, Identifiable, Associations, QueryableByName)]
#[diesel(belongs_to(User))]
#[diesel(table_name = posts)]
pub struct Post {
pub id: i32,
pub user_id: i32,
pub title: String,
pub body: Option<String>,
}

#[derive(Insertable)]
#[diesel(table_name = posts)]
pub struct NewPost {
Expand All @@ -99,14 +49,6 @@ impl NewPost {
}
}

#[derive(PartialEq, Eq, Debug, Clone, Queryable, Identifiable, Associations)]
#[diesel(belongs_to(Post))]
pub struct Comment {
id: i32,
post_id: i32,
text: String,
}

#[derive(Debug, Clone, Copy, Insertable)]
#[diesel(table_name = comments)]
pub struct NewComment<'a>(
Expand Down
61 changes: 4 additions & 57 deletions diesel_bench/benches/diesel_benches.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#[path = "common.rs"]
mod common;

use common::*;
use super::Bencher;
use diesel::*;

Expand All @@ -10,45 +14,6 @@ type TestConnection = MysqlConnection;
#[cfg(feature = "sqlite")]
type TestConnection = SqliteConnection;

table! {
users {
id -> Integer,
name -> Text,
hair_color -> Nullable<Text>,
}
}

table! {
posts {
id -> Integer,
user_id -> Integer,
title -> Text,
body -> Nullable<Text>,
}
}

table! {
comments {
id -> Integer,
post_id -> Integer,
text -> Text,
}
}

joinable!(comments -> posts (post_id));
joinable!(posts -> users (user_id));
allow_tables_to_appear_in_same_query!(users, posts, comments);

#[derive(
PartialEq, Eq, Debug, Clone, Queryable, Identifiable, Insertable, AsChangeset, QueryableByName,
)]
#[diesel(table_name = users)]
pub struct User {
pub id: i32,
pub name: String,
pub hair_color: Option<String>,
}

#[derive(Debug, PartialEq, Eq, Queryable, Clone, Insertable, AsChangeset)]
#[diesel(table_name = users)]
#[diesel(treat_none_as_default_value = false)]
Expand All @@ -66,16 +31,6 @@ impl NewUser {
}
}

#[derive(PartialEq, Eq, Debug, Clone, Queryable, Identifiable, Associations, QueryableByName)]
#[diesel(belongs_to(User))]
#[diesel(table_name = posts)]
pub struct Post {
pub id: i32,
pub user_id: i32,
pub title: String,
pub body: Option<String>,
}

#[derive(Insertable)]
#[diesel(table_name = posts)]
pub struct NewPost {
Expand All @@ -94,14 +49,6 @@ impl NewPost {
}
}

#[derive(PartialEq, Eq, Debug, Clone, Queryable, Identifiable, Associations)]
#[diesel(belongs_to(Post))]
pub struct Comment {
id: i32,
post_id: i32,
text: String,
}

#[derive(Debug, Clone, Copy, Insertable)]
#[diesel(table_name = comments)]
pub struct NewComment<'a>(
Expand Down
23 changes: 4 additions & 19 deletions diesel_bench/benches/mysql_benches.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
#[path = "common.rs"]
mod common;

use common::*;
use super::Bencher;
use rust_mysql::params::Params;
use rust_mysql::prelude::*;
use rust_mysql::{Conn, Opts, Row};
use std::collections::HashMap;

pub struct User {
pub id: i32,
pub name: String,
pub hair_color: Option<String>,
}

pub struct Post {
pub id: i32,
pub user_id: i32,
pub title: String,
pub body: Option<String>,
}

pub struct Comment {
pub id: i32,
pub post_id: i32,
pub text: String,
}

fn connection() -> Conn {
dotenvy::dotenv().ok();
let connection_url = dotenvy::var("MYSQL_DATABASE_URL")
Expand Down
23 changes: 4 additions & 19 deletions diesel_bench/benches/postgres_benches.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#[path = "common.rs"]
mod common;

use common::*;
use super::Bencher;
use rust_postgres::fallible_iterator::FallibleIterator;
use rust_postgres::types::ToSql;
Expand All @@ -6,25 +10,6 @@ use std::collections::HashMap;

const NO_PARAMS: Vec<&dyn ToSql> = Vec::new();

pub struct User {
pub id: i32,
pub name: String,
pub hair_color: Option<String>,
}

pub struct Post {
pub id: i32,
pub user_id: i32,
pub title: String,
pub body: Option<String>,
}

pub struct Comment {
pub id: i32,
pub post_id: i32,
pub text: String,
}

fn connection() -> Client {
dotenvy::dotenv().ok();
let connection_url = dotenvy::var("POSTGRES_DATABASE_URL")
Expand Down
26 changes: 4 additions & 22 deletions diesel_bench/benches/quaint_benches.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
#[path = "common.rs"]
mod common;

use common::*;
use super::Bencher;
use quaint::prelude::*;
use quaint::single::Quaint;
use serde::Deserialize;
use std::collections::HashMap;
use tokio::runtime::Runtime;

#[derive(Deserialize)]
pub struct User {
pub id: i32,
pub name: String,
pub hair_color: Option<String>,
}

#[derive(Deserialize)]
pub struct Post {
pub id: i32,
pub user_id: i32,
pub title: String,
pub body: Option<String>,
}

#[derive(Deserialize)]
pub struct Comment {
pub id: i32,
pub post_id: i32,
pub text: String,
}

#[derive(Deserialize)]
pub struct UserWithPost {
pub myuser_id: i32,
Expand Down
Loading
Loading