Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Bench to use a stable random from run to run #159

Merged
merged 1 commit into from
Mar 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions limitador/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ use rand::seq::SliceRandom;
use limitador::limit::Limit;
use limitador::storage::CounterStorage;
use limitador::RateLimiter;
use rand::SeedableRng;
use std::collections::HashMap;
use std::fmt::{Display, Formatter};

const SEED: u64 = 42;

#[cfg(not(feature = "redis"))]
criterion_group!(benches, bench_in_mem);
#[cfg(feature = "redis")]
Expand Down Expand Up @@ -131,8 +134,9 @@ fn bench_is_rate_limited(

let (rate_limiter, call_params) = generate_test_data(test_scenario, storage);

let rng = &mut rand::rngs::StdRng::seed_from_u64(SEED);
b.iter(|| {
let params = call_params.choose(&mut rand::thread_rng()).unwrap();
let params = call_params.choose(rng).unwrap();

black_box(
rate_limiter
Expand All @@ -154,8 +158,9 @@ fn bench_update_counters(
storage.clear().unwrap();
let (rate_limiter, call_params) = generate_test_data(test_scenario, storage);

let rng = &mut rand::rngs::StdRng::seed_from_u64(SEED);
b.iter(|| {
let params = call_params.choose(&mut rand::thread_rng()).unwrap();
let params = call_params.choose(rng).unwrap();

rate_limiter
.update_counters(
Expand All @@ -176,8 +181,9 @@ fn bench_check_rate_limited_and_update(
storage.clear().unwrap();
let (rate_limiter, call_params) = generate_test_data(test_scenario, storage);

let rng = &mut rand::rngs::StdRng::seed_from_u64(SEED);
b.iter(|| {
let params = call_params.choose(&mut rand::thread_rng()).unwrap();
let params = call_params.choose(rng).unwrap();

black_box(
rate_limiter
Expand Down