2021-05-25 17:09:14 +02:00
mod datasets_paths ;
2021-04-13 18:34:00 +02:00
mod utils ;
use criterion ::{ criterion_group , criterion_main } ;
use milli ::update ::Settings ;
use utils ::Conf ;
2024-12-02 18:13:56 +01:00
#[ cfg(not(windows)) ]
2022-08-10 12:31:09 +02:00
#[ global_allocator ]
static ALLOC : mimalloc ::MiMalloc = mimalloc ::MiMalloc ;
2021-04-13 18:34:00 +02:00
fn base_conf ( builder : & mut Settings ) {
2021-06-16 18:33:33 +02:00
let displayed_fields =
[ " id " , " title " , " album " , " artist " , " genre " , " country " , " released " , " duration " ]
. iter ( )
. map ( | s | s . to_string ( ) )
. collect ( ) ;
2021-04-13 18:34:00 +02:00
builder . set_displayed_fields ( displayed_fields ) ;
2021-06-16 18:33:33 +02:00
let searchable_fields = [ " title " , " album " , " artist " ] . iter ( ) . map ( | s | s . to_string ( ) ) . collect ( ) ;
builder . set_searchable_fields ( searchable_fields ) ;
let faceted_fields = [ " released-timestamp " , " duration-float " , " genre " , " country " , " artist " ]
2021-04-13 18:34:00 +02:00
. iter ( )
. map ( | s | s . to_string ( ) )
. collect ( ) ;
2021-06-03 10:33:42 +02:00
builder . set_filterable_fields ( faceted_fields ) ;
2021-04-13 18:34:00 +02:00
}
2021-06-16 18:33:33 +02:00
#[ rustfmt::skip ]
2021-04-13 18:34:00 +02:00
const BASE_CONF : Conf = Conf {
2021-05-25 17:09:14 +02:00
dataset : datasets_paths ::SMOL_SONGS ,
2021-04-13 18:34:00 +02:00
queries : & [
2021-04-14 13:13:33 +02:00
" john " , // 9097
" david " , // 4794
" charles " , // 1957
" david bowie " , // 1200
" michael jackson " , // 600
" thelonious monk " , // 303
" charles mingus " , // 142
" marcus miller " , // 60
" tamo " , // 13
2021-04-14 12:36:12 +02:00
" Notstandskomitee " , // 4
2021-04-13 18:34:00 +02:00
] ,
configure : base_conf ,
2021-05-25 17:55:45 +02:00
primary_key : Some ( " id " ) ,
2021-04-13 18:34:00 +02:00
.. Conf ::BASE
} ;
fn bench_songs ( c : & mut criterion ::Criterion ) {
2021-06-16 18:33:33 +02:00
let default_criterion : Vec < String > =
milli ::default_criteria ( ) . iter ( ) . map ( | criteria | criteria . to_string ( ) ) . collect ( ) ;
2021-04-13 18:34:00 +02:00
let default_criterion = default_criterion . iter ( ) . map ( | s | s . as_str ( ) ) ;
2021-06-16 18:33:33 +02:00
let asc_default : Vec < & str > =
2021-08-23 11:37:18 +02:00
std ::iter ::once ( " released-timestamp:asc " ) . chain ( default_criterion . clone ( ) ) . collect ( ) ;
2021-06-16 18:33:33 +02:00
let desc_default : Vec < & str > =
2021-08-23 11:37:18 +02:00
std ::iter ::once ( " released-timestamp:desc " ) . chain ( default_criterion . clone ( ) ) . collect ( ) ;
2021-04-13 18:34:00 +02:00
2021-04-14 12:36:12 +02:00
let basic_with_quote : Vec < String > = BASE_CONF
. queries
. iter ( )
. map ( | s | {
2021-06-16 18:33:33 +02:00
s . trim ( ) . split ( ' ' ) . map ( | s | format! ( r # ""{}""# , s ) ) . collect ::< Vec < String > > ( ) . join ( " " )
2021-04-14 12:36:12 +02:00
} )
. collect ( ) ;
2021-06-16 18:33:33 +02:00
let basic_with_quote : & [ & str ] =
& basic_with_quote . iter ( ) . map ( | s | s . as_str ( ) ) . collect ::< Vec < & str > > ( ) ;
2021-04-14 12:36:12 +02:00
2021-06-16 18:33:33 +02:00
#[ rustfmt::skip ]
2021-04-13 18:34:00 +02:00
let confs = & [
/* first we bench each criterion alone */
utils ::Conf {
group_name : " proximity " ,
queries : & [
" black saint sinner lady " ,
" les dangeureuses 1960 " ,
" The Disneyland Sing-Along Chorus " ,
" Under Great Northern Lights " ,
2021-04-13 18:39:34 +02:00
" 7000 Danses Un Jour Dans Notre Vie " ,
2021-04-13 18:34:00 +02:00
] ,
criterion : Some ( & [ " proximity " ] ) ,
optional_words : false ,
.. BASE_CONF
} ,
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 ,
.. BASE_CONF
} ,
utils ::Conf {
group_name : " words " ,
queries : & [
" the black saint and the sinner lady and the good doggo " , // four words to pop
2021-04-14 13:13:33 +02:00
" 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
2021-04-13 18:34:00 +02:00
" Bring Your Daughter To The Slaughter but now this is not part of the title " , // nine words to pop
2021-04-14 12:36:12 +02:00
" whathavenotnsuchforth and a good amount of words to pop to match the first one " , // 13
2021-04-13 18:34:00 +02:00
] ,
criterion : Some ( & [ " words " ] ) ,
.. BASE_CONF
} ,
utils ::Conf {
group_name : " asc " ,
2021-08-23 11:37:18 +02:00
criterion : Some ( & [ " released-timestamp:desc " ] ) ,
2021-04-13 18:34:00 +02:00
.. BASE_CONF
} ,
utils ::Conf {
group_name : " desc " ,
2021-08-23 11:37:18 +02:00
criterion : Some ( & [ " released-timestamp:desc " ] ) ,
2021-04-13 18:34:00 +02:00
.. BASE_CONF
} ,
2021-04-14 16:26:21 +02:00
2021-04-13 18:34:00 +02:00
/* then we bench the asc and desc criterion on top of the default criterion */
utils ::Conf {
group_name : " asc + default " ,
criterion : Some ( & asc_default [ .. ] ) ,
.. BASE_CONF
} ,
utils ::Conf {
group_name : " desc + default " ,
criterion : Some ( & desc_default [ .. ] ) ,
.. BASE_CONF
} ,
2021-04-14 16:26:21 +02:00
/* we bench the filters with the default request */
utils ::Conf {
group_name : " basic filter: <= " ,
2021-06-03 10:33:42 +02:00
filter : Some ( " released-timestamp <= 946728000 " ) , // year 2000
2021-04-14 16:26:21 +02:00
.. BASE_CONF
} ,
utils ::Conf {
group_name : " basic filter: TO " ,
2021-06-03 10:33:42 +02:00
filter : Some ( " released-timestamp 946728000 TO 1262347200 " ) , // year 2000 to 2010
2021-04-14 16:26:21 +02:00
.. BASE_CONF
} ,
utils ::Conf {
group_name : " big filter " ,
2021-06-03 10:33:42 +02:00
filter : Some ( " released-timestamp != 1262347200 AND (NOT (released-timestamp = 946728000)) AND (duration-float = 1 OR (duration-float 1.1 TO 1.5 AND released-timestamp > 315576000)) " ) ,
2021-04-14 16:26:21 +02:00
.. BASE_CONF
} ,
2021-04-13 18:34:00 +02:00
/* the we bench some global / normal search with all the default criterion in the default
* order * /
utils ::Conf {
group_name : " basic placeholder " ,
2021-04-14 13:13:33 +02:00
queries : & [ " " ] ,
2021-04-13 18:34:00 +02:00
.. BASE_CONF
} ,
utils ::Conf {
group_name : " basic without quote " ,
2021-04-14 12:36:12 +02:00
queries : & BASE_CONF
. queries
. iter ( )
. map ( | s | s . trim ( ) ) // we remove the space at the end of each request
. collect ::< Vec < & str > > ( ) ,
2021-04-13 18:34:00 +02:00
.. BASE_CONF
} ,
utils ::Conf {
group_name : " basic with quote " ,
2021-04-14 12:36:12 +02:00
queries : basic_with_quote ,
2021-04-13 18:34:00 +02:00
.. BASE_CONF
} ,
utils ::Conf {
group_name : " prefix search " ,
queries : & [
" s " , // 500k+ results
2021-04-14 16:26:21 +02:00
" a " , //
" b " , //
" i " , //
" x " , // only 7k results
2021-04-13 18:34:00 +02:00
] ,
.. BASE_CONF
} ,
2021-04-14 13:13:33 +02:00
] ;
2021-04-13 18:34:00 +02:00
utils ::run_benches ( c , confs ) ;
}
criterion_group! ( benches , bench_songs ) ;
criterion_main! ( benches ) ;