| Crates.io | auto_bench_fct_macros |
| lib.rs | auto_bench_fct_macros |
| version | 1.0.0 |
| created_at | 2025-07-24 13:26:05.366779+00 |
| updated_at | 2025-07-24 13:26:05.366779+00 |
| description | The macros of auto_bench_fct. |
| homepage | |
| repository | https://github.com/ClementGre/auto_bench_fct |
| max_upload_size | |
| id | 1766029 |
| size | 45,250 |
A library for automatically benchmarking function call count and execution time in Rust.
Minimal setup is required to use this library, a macro attribute is provided to enable automatic benchmarking of functions, and a function to print the results.
disable feature to disable the library, which will make the macros and
functions to do nothing, allowing to keep the code in production without performance overhead.disable_hy feature to disable only the call stack hierarchy tracking, which will
make the macros #[auto_bench_fct_hy] behave like #[auto_bench_fct].log feature to log the results using the log crate with the info level.
This crate supports multithreaded programs, and uses wall time to measure the execution time of
functions, which is suitable for most use cases.Run
cargo add auto_bench_fct
or add the following to your Cargo.toml:
[dependencies]
auto_bench_fct = "1"
Add the #[auto_bench_fct] macro attribute to a function to track its execution time and calls
count, or addd the #[auto_bench_fct_hy] macro attribute to track its execution time
and calls count both globally and in the call stack hierarchy.
#[auto_bench_fct]
or #[auto_bench_fct_hy] grouped by function using [print_bench_fct_results].#[auto_bench_fct_hy] grouped by
function and call stack context using [print_bench_fct_hy_results].Use the #[auto_bench_fct_hy] macro attribute for functions you want to benchmark, and
use #[auto_bench_fct] instead only if you want to exclude the function from the call stack
hierarchy.
When not wanting to debug the call stack hierarchy due to the performance overhead,
enable the feature disable_hy.
When not wanting to debug the function calls at all, enable the feature disable.
Recursive functions are supported and will be tracked correctly, tracking only the root function call execution time. Though, mutual recursion is not supported, meaning that if two functions call each other recursively, it may create a huge number of entries in the metrics.
This library is designed to be used in development and testing environments.
It may have a large performance overhead, mostly if used on recursive functions
or in functions with a large number of calls and a small execution time.
The macro #[auto_bench_fct_hy] has a larger performance overhead than #[auto_bench_fct]
and should not be used in non-heavy functions.
This library is licensed under the GNU General Public License v3.0 (GPL-3.0).