1#[macro_export]
2macro_rules! abs_file {
3 () => {
4 std::path::PathBuf::from(
5 std::env::var("CODSPEED_CARGO_WORKSPACE_ROOT")
6 .expect("Could not find CODSPEED_CARGO_WORKSPACE_ROOT env variable, make sure you are using the latest version of cargo-codspeed")
7 )
8 .join(file!())
9 .to_string_lossy()
10 };
11}
12
13#[macro_export]
14macro_rules! codspeed_uri {
15 ( $name:ident ) => {
16 format!("{}::{}", file!(), stringify!($name))
17 };
18 ( $function:path ) => {
19 format!("{}::{}", file!(), stringify!($function))
20 };
21}
22
23#[macro_export]
24macro_rules! codspeed_bench {
25 ( $name:ident, $bench_payload:expr) => {
26 pub fn $name(codspeed: &mut $crate::codspeed::CodSpeed) {
27 let uri = codspeed::codspeed_uri!($name);
28 codspeed.start_benchmark(uri.as_str());
29 $crate::codspeed::black_box($bench_payload());
30 codspeed.end_benchmark();
31 }
32 };
33}
34
35#[macro_export]
36macro_rules! codspeed_main {
37 ( $( $target:path ),+ $(,)* ) => {
38 fn main() {
39 $crate::codspeed::display_native_harness();
40 let mut codspeed = $crate::codspeed::CodSpeed::new();
41 $(
42 $target(&mut codspeed);
43 )+
44
45 }
46 }
47}