diff --git a/milli/Cargo.toml b/milli/Cargo.toml index 156518e19..399b04428 100644 --- a/milli/Cargo.toml +++ b/milli/Cargo.toml @@ -61,13 +61,5 @@ rand = "0.8.3" default = [] [[bench]] -name = "typo" -harness = false - -[[bench]] -name = "words" -harness = false - -[[bench]] -name = "proximity" +name = "criterion" harness = false diff --git a/milli/benches/criterion.rs b/milli/benches/criterion.rs new file mode 100644 index 000000000..3f0b6d6b7 --- /dev/null +++ b/milli/benches/criterion.rs @@ -0,0 +1,58 @@ +mod utils; + +use criterion::{criterion_group, criterion_main}; + +fn bench_criterion(c: &mut criterion::Criterion) { + let confs = &[ + utils::Conf { + group_name: "proximity", + queries: &[ + "black saint sinner lady ", + "les dangeureuses 1960 ", + "The Disneyland Sing-Along Chorus ", + "Under Great Northern Lights ", + "7000 Danses Un Jour Dans Notre Vie", + ], + criterion: Some(&["proximity"]), + optional_words: false, + }, + utils::Conf { + group_name: "typo", + queries: &[ + "mongus ", + "thelonius monk ", + "Disnaylande ", + "the white striper ", + "indochie ", + "indochien ", + "klub des loopers ", + "fear of the duck ", + "michel depech ", + "stromal ", + "dire straights ", + "Arethla Franklin ", + ], + criterion: Some(&["typo"]), + optional_words: false, + }, + utils::Conf { + group_name: "words", + queries: &[ + "the black saint and the sinner lady and the good doggo ", // four words to pop + "les liaisons dangeureuses 1793 ", // one word to pop + "The Disneyland Children's Sing-Alone song ", // two words to pop + "seven nation mummy ", // one word to pop + "7000 Danses / Le Baiser / je me trompe de mots ", // four words to pop + "Bring Your Daughter To The Slaughter but now this is not part of the title ", // nine words to pop + "whathavenotnsuchforth and then a good amount of words tot pop in order to match the first one ", // 16 + ], + criterion: Some(&["words"]), + optional_words: true, + } + ]; + + utils::run_benches(c, confs); +} + +criterion_group!(benches, bench_criterion); +criterion_main!(benches); diff --git a/milli/benches/proximity.rs b/milli/benches/proximity.rs deleted file mode 100644 index 5b687855f..000000000 --- a/milli/benches/proximity.rs +++ /dev/null @@ -1,33 +0,0 @@ -mod utils; - -use std::time::Duration; -use criterion::{criterion_group, criterion_main, BenchmarkId}; - -fn bench_proximity(c: &mut criterion::Criterion) { - let index = utils::base_setup(Some(vec!["words".to_string()])); - - let queries = [ - "black saint sinner lady ", - "les dangeureuses 1960 ", - "The Disneyland Sing-Alone song ", - "Under Great Northern Lights ", - "7000 Danses Un Jour Dans Notre Vie", - ]; - - let mut group = c.benchmark_group("proximity"); - group.measurement_time(Duration::from_secs(10)); - - for query in &queries { - group.bench_with_input(BenchmarkId::from_parameter(query), &query, |b, &query| { - b.iter(|| { - let rtxn = index.read_txn().unwrap(); - let _documents_ids = index.search(&rtxn).query(*query).optional_words(false).execute().unwrap(); - }); - }); - } - - group.finish(); -} - -criterion_group!(benches, bench_proximity); -criterion_main!(benches); diff --git a/milli/benches/typo.rs b/milli/benches/typo.rs deleted file mode 100644 index 184f1e5df..000000000 --- a/milli/benches/typo.rs +++ /dev/null @@ -1,40 +0,0 @@ -mod utils; - -use std::time::Duration; -use criterion::{criterion_group, criterion_main, BenchmarkId}; - -fn bench_typo(c: &mut criterion::Criterion) { - let index = utils::base_setup(Some(vec!["typo".to_string()])); - - let queries = [ - "mongus ", - "thelonius monk ", - "Disnaylande ", - "the white striper ", - "indochie ", - "indochien ", - "klub des loopers ", - "fear of the duck ", - "michel depech ", - "stromal ", - "dire straights ", - "Arethla Franklin ", - ]; - - let mut group = c.benchmark_group("typo"); - group.measurement_time(Duration::from_secs(10)); - - for query in &queries { - group.bench_with_input(BenchmarkId::from_parameter(query), &query, |b, &query| { - b.iter(|| { - let rtxn = index.read_txn().unwrap(); - let _documents_ids = index.search(&rtxn).query(*query).optional_words(false).execute().unwrap(); - }); - }); - } - - group.finish(); -} - -criterion_group!(benches, bench_typo); -criterion_main!(benches); diff --git a/milli/benches/utils.rs b/milli/benches/utils.rs index 23c47ea76..c608a3ef3 100644 --- a/milli/benches/utils.rs +++ b/milli/benches/utils.rs @@ -1,9 +1,17 @@ -use std::{fs::{File, create_dir_all}}; +use std::{fs::{File, create_dir_all}, time::Duration}; use heed::EnvOpenOptions; +use criterion::BenchmarkId; use milli::{Index, update::{IndexDocumentsMethod, UpdateBuilder, UpdateFormat}}; -pub fn base_setup(criteria: Option>) -> Index { +pub struct Conf<'a> { + pub group_name: &'a str, + pub queries: &'a[&'a str], + pub criterion: Option<&'a [&'a str]>, + pub optional_words: bool, +} + +pub fn base_setup(criterion: Option>) -> Index { let database = "songs.mmdb"; create_dir_all(&database).unwrap(); @@ -16,12 +24,12 @@ pub fn base_setup(criteria: Option>) -> Index { let mut wtxn = index.write_txn().unwrap(); let mut builder = update_builder.settings(&mut wtxn, &index); - if let Some(criteria) = criteria { + if let Some(criterion) = criterion { builder.reset_faceted_fields(); builder.reset_criteria(); builder.reset_stop_words(); - builder.set_criteria(criteria); + builder.set_criteria(criterion); } builder.execute(|_, _| ()).unwrap(); @@ -39,3 +47,23 @@ pub fn base_setup(criteria: Option>) -> Index { index } + +pub fn run_benches(c: &mut criterion::Criterion, confs: &[Conf]) { + for conf in confs { + let criterion = conf.criterion.map(|s| s.iter().map(|s| s.to_string()).collect()); + let index = base_setup(criterion); + + let mut group = c.benchmark_group(conf.group_name); + group.measurement_time(Duration::from_secs(10)); + + for &query in conf.queries { + group.bench_with_input(BenchmarkId::from_parameter(query), &query, |b, &query| { + b.iter(|| { + let rtxn = index.read_txn().unwrap(); + let _documents_ids = index.search(&rtxn).query(query).optional_words(conf.optional_words).execute().unwrap(); + }); + }); + } + group.finish(); + } +} diff --git a/milli/benches/words.rs b/milli/benches/words.rs deleted file mode 100644 index 92ca0a784..000000000 --- a/milli/benches/words.rs +++ /dev/null @@ -1,35 +0,0 @@ -mod utils; - -use std::time::Duration; -use criterion::{criterion_group, criterion_main, BenchmarkId}; - -fn bench_words(c: &mut criterion::Criterion) { - let index = utils::base_setup(Some(vec!["words".to_string()])); - - let queries = [ - "the black saint and the sinner lady and the good doggo ", // four words to pop - "les liaisons dangeureuses 1793 ", // one word to pop - "The Disneyland Children's Sing-Alone song ", // two words to pop - "seven nation mummy ", // one word to pop - "7000 Danses / Le Baiser / je me trompe de mots ", // four words to pop - "Bring Your Daughter To The Slaughter but now this is not part of the title ", // nine words to pop - "whathavenotnsuchforth and then a good amount of words tot pop in order to match the first one ", // 16 - ]; - - let mut group = c.benchmark_group("words"); - group.measurement_time(Duration::from_secs(10)); - - for query in &queries { - group.bench_with_input(BenchmarkId::from_parameter(query), &query, |b, &query| { - b.iter(|| { - let rtxn = index.read_txn().unwrap(); - let _documents_ids = index.search(&rtxn).query(*query).execute().unwrap(); - }); - }); - } - - group.finish(); -} - -criterion_group!(benches, bench_words); -criterion_main!(benches);