2023-11-18 13:55:01 +00:00
|
|
|
use criterion::Criterion;
|
2024-09-05 08:04:12 +00:00
|
|
|
use std::sync::LazyLock;
|
2023-11-18 13:55:01 +00:00
|
|
|
use std::sync::OnceLock;
|
|
|
|
use tokio::runtime::Runtime;
|
|
|
|
|
|
|
|
mod lib;
|
|
|
|
mod sdk;
|
|
|
|
|
2024-09-05 08:04:12 +00:00
|
|
|
static NUM_OPS: LazyLock<usize> =
|
|
|
|
LazyLock::new(|| std::env::var("BENCH_NUM_OPS").unwrap_or("1000".to_string()).parse().unwrap());
|
|
|
|
static DURATION_SECS: LazyLock<u64> =
|
|
|
|
LazyLock::new(|| std::env::var("BENCH_DURATION").unwrap_or("30".to_string()).parse().unwrap());
|
|
|
|
static SAMPLE_SIZE: LazyLock<usize> = LazyLock::new(|| {
|
|
|
|
std::env::var("BENCH_SAMPLE_SIZE").unwrap_or("30".to_string()).parse().unwrap()
|
|
|
|
});
|
|
|
|
static WORKER_THREADS: LazyLock<usize> = LazyLock::new(|| {
|
|
|
|
std::env::var("BENCH_WORKER_THREADS").unwrap_or("1".to_string()).parse().unwrap()
|
|
|
|
});
|
2023-11-18 13:55:01 +00:00
|
|
|
static RUNTIME: OnceLock<Runtime> = OnceLock::new();
|
|
|
|
|
|
|
|
fn rt() -> &'static Runtime {
|
|
|
|
RUNTIME.get_or_init(|| {
|
|
|
|
tokio::runtime::Builder::new_multi_thread()
|
2023-12-09 20:25:50 +00:00
|
|
|
.worker_threads(*WORKER_THREADS)
|
2023-11-18 13:55:01 +00:00
|
|
|
.enable_all()
|
|
|
|
.build()
|
|
|
|
.unwrap()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create a benchmark group for the given target.
|
|
|
|
pub(super) fn benchmark_group(c: &mut Criterion, target: String) {
|
|
|
|
println!("### Benchmark config: target={}, num_ops={}, duration={}, sample_size={}, worker_threads={} ###", target, *NUM_OPS, *DURATION_SECS, *SAMPLE_SIZE, *WORKER_THREADS);
|
|
|
|
|
|
|
|
match &target {
|
|
|
|
t if t.starts_with("lib") => lib::benchmark_group(c, target),
|
|
|
|
t if t.starts_with("sdk") => sdk::benchmark_group(c, target),
|
|
|
|
t => panic!("Target '{}' not supported.", t),
|
|
|
|
}
|
|
|
|
}
|