#[must_use]
#[expect(
clippy::missing_const_for_fn,
reason = "wasm diagnostics uses the non-const IC performance counter"
)]
pub(in crate::db) fn read_local_instruction_counter() -> u64 {
#[cfg(all(feature = "diagnostics", target_arch = "wasm32"))]
{
canic_cdk::api::performance_counter(1)
}
#[cfg(not(all(feature = "diagnostics", target_arch = "wasm32")))]
{
0
}
}
pub(in crate::db) fn measure_local_instruction_delta<T>(run: impl FnOnce() -> T) -> (u64, T) {
let start = read_local_instruction_counter();
let result = run();
let delta = read_local_instruction_counter().saturating_sub(start);
(delta, result)
}