<commit_before>use std::time::Duration;
use criterion::{Criterion,black_box,Bencher};

use pleco::{Board};

use pleco_engine::engine::PlecoSearcher;
use pleco_engine::time::uci_timer::PreLimits;

use super::*;


fn search_3moves_engine<D: DepthLimit>(b: &mut Bencher) {
    let mut limit = PreLimits::blank();
    limit.depth = Some(D::depth());
    b.iter_with_setup(|| {
        let mut s = PlecoSearcher::init(false);
        s.clear_search();
        (Board::default(), s)
    }, |(mut board, mut s)| {
        black_box(s.search(&board, &limit));
        let mov = black_box(s.await_move());
        board.apply_move(mov);
        black_box(s.search(&board, &limit));
        let mov = black_box(s.await_move());
        board.apply_move(mov);
        black_box(s.search(&board, &limit));
        black_box(s.await_move());
    })
}

fn bench_engine_evaluations(c: &mut Criterion) {
    c.bench_function("Search MuliMove Depth 4", search_3moves_engine::<Depth4>);
    c.bench_function("Search MuliMove Depth 5", search_3moves_engine::<Depth5>);
    c.bench_function("Search MuliMove Depth 6", search_3moves_engine::<Depth6>);
    c.bench_function("Search MuliMove Depth 7", search_3moves_engine::<Depth7>);
}

criterion_group!(name = search_multimove;
     config = Criterion::default()
        .sample_size(16)
        .warm_up_time(Duration::from_millis(200));
    targets = bench_engine_evaluations
);
<commit_msg>Hopefully reducing the sample size prevents a stack allocation error.<commit_after>use std::time::Duration;
use criterion::{Criterion,black_box,Bencher};

use pleco::{Board};

use pleco_engine::engine::PlecoSearcher;
use pleco_engine::time::uci_timer::PreLimits;

use super::*;


fn search_3moves_engine<D: DepthLimit>(b: &mut Bencher) {
    let mut limit = PreLimits::blank();
    limit.depth = Some(D::depth());
    b.iter_with_setup(|| {
        let mut s = PlecoSearcher::init(false);
        s.clear_search();
        (Board::default(), s)
    }, |(mut board, mut s)| {
        black_box(s.search(&board, &limit));
        let mov = black_box(s.await_move());
        board.apply_move(mov);
        black_box(s.search(&board, &limit));
        let mov = black_box(s.await_move());
        board.apply_move(mov);
        black_box(s.search(&board, &limit));
        black_box(s.await_move());
    })
}

fn bench_engine_evaluations(c: &mut Criterion) {
    c.bench_function("Search MuliMove Depth 4", search_3moves_engine::<Depth4>);
    c.bench_function("Search MuliMove Depth 5", search_3moves_engine::<Depth5>);
    c.bench_function("Search MuliMove Depth 6", search_3moves_engine::<Depth6>);
    c.bench_function("Search MuliMove Depth 7", search_3moves_engine::<Depth7>);
}

criterion_group!(name = search_multimove;
     config = Criterion::default()
        .sample_size(12)
        .warm_up_time(Duration::from_millis(200));
    targets = bench_engine_evaluations
);

{'fraction_non_alphanumeric': 0.1520689655172414, 'fraction_numerical': 0.012413793103448275, 'mean_word_length': 4.227027027027027, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '4115257', 'n_tokens_mistral': 1012, 'n_tokens_neox': 1016, 'n_words': 173}