Wado

core:fuel

The deterministic cost of a region of a test.

[measure] runs a closure and, under wado test --report-fuel, reports the fuel it spent: each Wasm instruction the guest ran, priced near the time it takes (an i32.add costs 2). Fuel does not depend on the host, so one run gives a figure that only a change to the program or to wasmtime moves. The prices are approximate, and an allocation's share of collection grows with the live set, which no price sees.

Without --report-fuel the closure just runs. Only wado test supports it, and a program for any other world that reaches this module does not compile.

Synopsis

let n = builtin::black_box(1_000);
let sum = measure("sum", || {
    let mut s = 0;
    for let i of 0..<n {
        s += i;
    }
    return s;
});
assert sum == 499_500;

Functions

pub fn measure<T, effect E>(label: String, mut f: fn mut() -> T with E) -> T with (E, FuelHost)

Runs f and reports the fuel it spent as region label of the running test. f's result passes through builtin::black_box, so the work that produces it is never optimized out of the region.

Effects

pub interface FuelHost

Host interface behind core:fuel. Only wado test supplies it, and only under --report-fuel does it meter.

fn spent() -> Option<u64>

#[cm("core:fuel/fuel-host@0.1.0#spent")]

The fuel the running test has spent so far, or none when the run is not metered.

fn report(label: String, fuel: u64)

#[cm("core:fuel/fuel-host@0.1.0#report")] #[cm_params("label", "fuel")]

Region label of the running test spent fuel.