<commit_before>#![feature(test)]
#[macro_use]
extern crate yaqb;
extern crate test;

mod schema;

use self::test::Bencher;
use self::schema::*;

#[bench]
fn bench_selecting_10k_rows(b: &mut Bencher) {
    let conn = connection();
    setup_users_table(&conn);
    let data: Vec<_> = (0..10_000).map(|i| {
        NewUser::new(&format!("User {}", i), None)
    }).collect();
    conn.insert_returning_count(&users::table, &data).unwrap();

    b.iter(|| {
        conn.query_all(users::table).unwrap().collect::<Vec<User>>()
    })
}<commit_msg>Add a few additional benchmarks<commit_after>#![feature(test)]
#[macro_use]
extern crate yaqb;
extern crate test;

mod schema;

use self::test::Bencher;
use self::schema::*;
use yaqb::*;

#[bench]
fn bench_selecting_0_rows_with_trivial_query(b: &mut Bencher) {
    let conn = connection();
    setup_users_table(&conn);

    b.iter(|| {
        conn.query_all(users::table).unwrap().collect::<Vec<User>>()
    })
}

#[bench]
fn bench_selecting_10k_rows_with_trivial_query(b: &mut Bencher) {
    let conn = connection();
    setup_users_table(&conn);
    let data: Vec<_> = (0..10_000).map(|i| {
        NewUser::new(&format!("User {}", i), None)
    }).collect();
    conn.insert_returning_count(&users::table, &data).unwrap();

    b.iter(|| {
        conn.query_all(users::table).unwrap().collect::<Vec<User>>()
    })
}

#[bench]
fn bench_selecting_0_rows_with_medium_complex_query(b: &mut Bencher) {
    let conn = connection();
    setup_users_table(&conn);
    setup_posts_table(&conn);

    b.iter(|| {
        use schema::users::dsl::*;
        let target = users.left_outer_join(posts::table)
            .filter(hair_color.eq("black"))
            .order(name.desc());
        conn.query_all(target).unwrap().collect::<Vec<(User, Option<Post>)>>()
    })
}

#[bench]
fn bench_selecting_10k_rows_with_medium_complex_query(b: &mut Bencher) {
    let conn = connection();
    setup_users_table(&conn);
    setup_posts_table(&conn);

    let data: Vec<_> = (0..10_000).map(|i| {
        let hair_color = if i % 2 == 0 { "black" } else { "brown" };
        NewUser::new(&format!("User {}", i), Some(hair_color))
    }).collect();
    conn.insert_returning_count(&users::table, &data).unwrap();

    b.iter(|| {
        use schema::users::dsl::*;
        let target = users.left_outer_join(posts::table)
            .filter(hair_color.eq("black"))
            .order(name.desc());
        conn.query_all(target).unwrap().collect::<Vec<(User, Option<Post>)>>()
    })
}
{'fraction_non_alphanumeric': 0.19197138314785372, 'fraction_numerical': 0.011128775834658187, 'mean_word_length': 3.7760910815939277, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '568151', 'n_tokens_mistral': 901, 'n_tokens_neox': 896, 'n_words': 146}