wrk_api_bench/
benchmark.rs

1use std::time::Duration;
2
3use getset::{Getters, MutGetters, Setters};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Default, PartialEq, Hash, Clone, Serialize, Deserialize, Getters, Setters, MutGetters, Builder)]
7pub struct Benchmark {
8    #[builder(default = "8")]
9    #[getset(get = "pub", set = "pub", get_mut = "pub")]
10    threads: u16,
11    #[builder(default = "32")]
12    #[getset(get = "pub", set = "pub", get_mut = "pub")]
13    connections: u16,
14    #[builder(default = "Duration::from_secs(30)")]
15    #[getset(get = "pub", set = "pub", get_mut = "pub")]
16    duration: Duration,
17}
18
19impl BenchmarkBuilder {
20    pub fn exponential(duration: Option<Duration>) -> Vec<Benchmark> {
21        let duration = duration.unwrap_or_else(|| Duration::from_secs(30));
22        let threads_list = [2, 4, 8, 16];
23        let connections_list = [32, 64, 128, 256];
24        let mut benchmarks = Vec::new();
25        for threads in threads_list {
26            for connections in connections_list {
27                benchmarks.push(Benchmark {
28                    threads,
29                    connections,
30                    duration,
31                });
32            }
33        }
34        benchmarks
35    }
36}
37
38impl Benchmark {
39    pub fn new(threads: u16, connections: u16, duration: u64) -> Self {
40        Self {
41            threads,
42            connections,
43            duration: Duration::from_secs(duration),
44        }
45    }
46}