pub const NBSECONDS: u32 = 3;
pub const TIMELOOP_MICROSEC: u64 = 1_000_000;
pub const TIMELOOP_NANOSEC: u64 = 1_000_000_000;
pub const ACTIVEPERIOD_NANOSEC: u64 = 70 * 1_000_000_000;
pub const COOLPERIOD_SEC: u64 = 10;
pub const DECOMP_MULT: u32 = 1;
pub const KB: usize = 1 << 10;
pub const MB: usize = 1 << 20;
pub const GB: usize = 1 << 30;
pub const LZ4_MAX_DICT_SIZE: usize = 64 * KB;
pub const MAX_MEMORY: usize = if usize::BITS == 32 {
(2 * GB) - (64 * MB)
} else {
1usize << (usize::BITS - 31)
};
#[derive(Debug, Clone)]
pub struct BenchConfig {
pub display_level: u32,
pub nb_seconds: u32,
pub block_size: usize,
pub additional_param: i32,
pub bench_separately: bool,
pub decode_only: bool,
pub skip_checksums: bool,
}
impl Default for BenchConfig {
fn default() -> Self {
BenchConfig {
display_level: 2,
nb_seconds: NBSECONDS,
block_size: 0,
additional_param: 0,
bench_separately: false,
decode_only: false,
skip_checksums: false,
}
}
}
impl BenchConfig {
pub fn set_notification_level(&mut self, level: u32) -> &mut Self {
self.display_level = level;
self
}
pub fn set_additional_param(&mut self, additional_param: i32) -> &mut Self {
self.additional_param = additional_param;
self
}
pub fn set_nb_seconds(&mut self, nb_seconds: u32) -> &mut Self {
self.nb_seconds = nb_seconds;
self
}
pub fn set_block_size(&mut self, block_size: usize) -> &mut Self {
self.block_size = block_size;
self
}
pub fn set_bench_separately(&mut self, separate: bool) -> &mut Self {
self.bench_separately = separate;
self
}
pub fn set_decode_only(&mut self, set: bool) -> &mut Self {
self.decode_only = set;
self
}
pub fn set_skip_checksums(&mut self, skip: bool) -> &mut Self {
self.skip_checksums = skip;
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_nb_seconds() {
assert_eq!(BenchConfig::default().nb_seconds, 3);
}
#[test]
fn default_block_size() {
assert_eq!(BenchConfig::default().block_size, 0);
}
#[test]
fn default_display_level() {
assert_eq!(BenchConfig::default().display_level, 2);
}
#[test]
fn setter_nb_seconds() {
let mut cfg = BenchConfig::default();
cfg.set_nb_seconds(10);
assert_eq!(cfg.nb_seconds, 10);
}
#[test]
fn setter_block_size() {
let mut cfg = BenchConfig::default();
cfg.set_block_size(64 * KB);
assert_eq!(cfg.block_size, 65536);
}
#[test]
fn setter_chain() {
let mut cfg = BenchConfig::default();
cfg.set_nb_seconds(5)
.set_block_size(1 * MB)
.set_decode_only(true)
.set_skip_checksums(true);
assert_eq!(cfg.nb_seconds, 5);
assert_eq!(cfg.block_size, MB);
assert!(cfg.decode_only);
assert!(cfg.skip_checksums);
}
#[test]
fn setter_bench_separately_false() {
let mut cfg = BenchConfig::default();
cfg.set_bench_separately(false);
assert!(!cfg.bench_separately);
}
#[test]
fn constants_sanity() {
assert_eq!(KB, 1024);
assert_eq!(MB, 1024 * 1024);
assert_eq!(LZ4_MAX_DICT_SIZE, 65536);
assert_eq!(TIMELOOP_MICROSEC, 1_000_000);
assert_eq!(TIMELOOP_NANOSEC, 1_000_000_000);
assert_eq!(ACTIVEPERIOD_NANOSEC, 70_000_000_000);
}
}