Macro compute_fn

Source
macro_rules! compute_fn {
    ($msg:expr=> $($tt:tt)*) => { ... };
}
Expand description

Original here A macro for logging compute units used by a specific code block.

This macro wraps a code block, logging the compute units before and after its execution. It also adds opening and closing log messages for easier tracking in the program output.

§Arguments

  • $msg - A string literal used as a label for the logged block.
  • $($tt)* - The code block to be executed and measured.

§Returns

Returns the result of the executed code block.

§Note

This macro consumes an additional 409 compute units per call due to the logging operations.

§Examples

use solana_program;
sol_dev_macros::compute_fn!("My Operation" => {
    // Your code here
    42
});

§References