1

I know I can get this by trial and error and just running the operations I want to test it, but I'd imagine it's written down somewhere too. Where?

2 Answers 2

2

Found my answer in the end, the CU amount per syscall can be found in the codebase here.

1

Check out this, by Jonas,

https://github.com/solana-developers/cu_optimizations?tab=readme-ov-file#how-to-measure-cu

The best way to measure CU is to use the solana program log.

/// Total extra compute units used per compute_fn! call 409 CU
/// https://github.com/anza-xyz/agave/blob/d88050cda335f87e872eddbdf8506bc063f039d3/programs/bpf_loader/src/syscalls/logging.rs#L70
/// https://github.com/anza-xyz/agave/blob/d88050cda335f87e872eddbdf8506bc063f039d3/program-runtime/src/compute_budget.rs#L150
#[macro_export]
macro_rules! compute_fn {
    ($msg:expr=> $($tt:tt)*) => {
        ::solana_program::msg!(concat!($msg, " {"));
        ::solana_program::log::sol_log_compute_units();
        let res = { $($tt)* };
        ::solana_program::log::sol_log_compute_units();
        ::solana_program::msg!(concat!(" } // ", $msg));
        res
    };
}

You put it in front and after the code block you want to measure like so:

compute_fn!("My message" => {
    // Your code here
});
3
  • 1
    I'm aware of this, but this forces me to run the computation to find out how many CUs it costs. I meant in the sense of wanting to know how many CUs e.g. adding two u64s together costs, which I assume is written down somewhere.
    – McBain
    Commented May 12 at 19:56
  • Do you mean like a reference of how many CUs these operations take up, something similar to the space reference?
    – Jimii
    Commented May 12 at 21:05
  • yes, that's exactly what I mean
    – McBain
    Commented May 12 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.