Crates.io | performance-mark-attribute |
lib.rs | performance-mark-attribute |
version | 0.2.2 |
source | src |
created_at | 2023-05-15 12:18:17.036993 |
updated_at | 2023-05-15 15:34:07.153585 |
description | performance_mark is an attribute macro that adds performance (time) logging to methods. |
homepage | |
repository | https://github.com/Jamalam360/performance-mark |
max_upload_size | |
id | 864967 |
size | 6,626 |
performance_mark
is an attribute macro that adds performance (time) logging to
functions. By default, it uses println!
, but can be configured to use a custom
method.
Basic example:
use performance_mark_attribute::performance_mark;
#[performance_mark]
fn test_function_logged_using_stdout() {
println!("Hello!");
}
Output:
(performance_mark) test_function_logged_using_stdout took 7.177µs
use performance_mark_attribute::{performance_mark, LogContext}
#[performance_mark(log_with_this)]
fn test_function_logged_using_custom_function() {
println!("Hello!");
}
fn log_with_this(ctx: LogContext) {
println!("Function: {} , Time: {}ms", ctx.function, ctx.duration);
}
use performance_mark_attribute::{performance_mark, LogContext}
#[performance_mark(async log_with_this)]
fn test_function_logged_using_custom_function() {
println!("Hello!");
}
async fn log_with_this(ctx: LogContext) {
// Log asynchronously
}