<commit_before>#![feature(test)]

extern crate test;
extern crate ratelimit_meter;

use ratelimit_meter::{GCRA, Threadsafe, Decider};
use ratelimit_meter::example_algorithms::Allower;
use std::time::{Instant, Duration};

#[bench]
fn bench_gcra(b: &mut test::Bencher) {
    let mut gcra = GCRA::for_capacity(50).unwrap().cell_weight(1).unwrap().build();
    let now = Instant::now();
    let ms = Duration::from_millis(20);
    let mut i = 0;
    b.iter(|| {
        i += 1;
        gcra.check_at(now + (ms * i)).unwrap();
    });
}

#[bench]
fn bench_allower(b: &mut test::Bencher) {
    let mut allower = Allower::new();
    b.iter(|| allower.check().unwrap());
}

#[bench]
fn bench_threadsafe_gcra(b: &mut test::Bencher) {
    let mut gcra = GCRA::for_capacity(50).unwrap().cell_weight(1).unwrap().build_sync();
    let now = Instant::now();
    let ms = Duration::from_millis(20);
    let mut i = 0;
    b.iter(|| {
        i += 1;
        gcra.check_at(now + (ms * i)).unwrap();
    });
}

#[bench]
fn bench_threadsafe_allower(b: &mut test::Bencher) {
    let allower_one = Allower::new();
    let mut threadsafe_allower = Threadsafe::new(allower_one);
    b.iter(|| threadsafe_allower.check());
}<commit_msg>Add a benchmark for the multi-cell GCRA decider<commit_after>#![feature(test)]

extern crate test;
extern crate ratelimit_meter;

use ratelimit_meter::{GCRA, Threadsafe, Decider, MultiDecider};
use ratelimit_meter::example_algorithms::Allower;
use std::time::{Instant, Duration};

#[bench]
fn bench_gcra(b: &mut test::Bencher) {
    let mut gcra = GCRA::for_capacity(50).unwrap().cell_weight(1).unwrap().build();
    let now = Instant::now();
    let ms = Duration::from_millis(20);
    let mut i = 0;
    b.iter(|| {
        i += 1;
        gcra.check_at(now + (ms * i)).unwrap();
    });
}

#[bench]
fn bench_gcra_bulk(b: &mut test::Bencher) {
    let mut gcra = GCRA::for_capacity(500).unwrap().cell_weight(1).unwrap().build();
    let now = Instant::now();
    let ms = Duration::from_millis(20);
    let mut i = 0;
    b.iter(|| {
        i += 1;
        gcra.check_n_at(10, now + (ms * i)).unwrap();
    });
}

#[bench]
fn bench_allower(b: &mut test::Bencher) {
    let mut allower = Allower::new();
    b.iter(|| allower.check().unwrap());
}

#[bench]
fn bench_threadsafe_gcra(b: &mut test::Bencher) {
    let mut gcra = GCRA::for_capacity(50).unwrap().cell_weight(1).unwrap().build_sync();
    let now = Instant::now();
    let ms = Duration::from_millis(20);
    let mut i = 0;
    b.iter(|| {
        i += 1;
        gcra.check_at(now + (ms * i)).unwrap();
    });
}

#[bench]
fn bench_threadsafe_allower(b: &mut test::Bencher) {
    let allower_one = Allower::new();
    let mut threadsafe_allower = Threadsafe::new(allower_one);
    b.iter(|| threadsafe_allower.check());
}
{'fraction_non_alphanumeric': 0.182987848463188, 'fraction_numerical': 0.013581129378127233, 'mean_word_length': 3.8010291595197256, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5272408', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1058, 'n_words': 216}