#![allow(missing_docs, reason = "no need for API documentation on benchmark code")]
#![allow(
clippy::needless_pass_by_value,
reason = "gungraun benchmark inputs are passed and returned by value by the framework"
)]
#![cfg_attr(
target_os = "linux",
expect(
clippy::exit,
clippy::missing_docs_in_private_items,
unused_qualifications,
reason = "Triggered by Gungraun macro expansion. Upstream tracking issues are pending."
)
)]
#[cfg(not(target_os = "linux"))]
fn main() {
}
#[cfg(target_os = "linux")]
mod linux {
use std::hint::black_box;
use bytesbuf::BytesBuf;
use bytesbuf::mem::testing::TransparentMemory;
use gungraun::{library_benchmark, library_benchmark_group};
const RESERVE_BYTES: usize = 4096;
const WRITE: &[u8] = &[0xAB; 16];
fn reserved() -> BytesBuf {
TransparentMemory::new().reserve(RESERVE_BYTES)
}
#[library_benchmark]
#[bench::single_span(reserved())]
fn bytes_buf_put_slice(mut buf: BytesBuf) -> BytesBuf {
buf.put_slice(black_box(WRITE));
buf
}
#[library_benchmark]
#[bench::single_span(reserved())]
fn bytes_buf_put_num_le(mut buf: BytesBuf) -> BytesBuf {
buf.put_num_le(black_box(0x1234_5678_u32));
buf
}
library_benchmark_group!(
name = bytes_buf;
benchmarks = bytes_buf_put_slice, bytes_buf_put_num_le
);
}
#[cfg(target_os = "linux")]
use gungraun::{Callgrind, LibraryBenchmarkConfig};
#[cfg(target_os = "linux")]
pub use linux::bytes_buf;
#[cfg(target_os = "linux")]
gungraun::main!(
config = LibraryBenchmarkConfig::default()
.tool(Callgrind::with_args(["--branch-sim=yes"]));
library_benchmark_groups = bytes_buf
);