Example Plot Line

"""Auto-generated example: Plot Type: Line."""

import bencher as bn

import math


class LatencyProfile(bn.ParametrizedSweep):
    """Latency as a function of load."""

    load = bn.FloatSweep(default=0.5, bounds=[0.0, 1.0])

    distance = bn.ResultFloat("m", doc="Latency distance metric")

    def benchmark(self):
        self.distance = math.sin(math.pi * self.load) + 0.5


def example_plot_line(run_cfg: bn.BenchRunCfg | None = None) -> bn.Bench:
    """Plot Type: Line."""
    bench = LatencyProfile().to_bench(run_cfg)
    res = bench.plot_sweep(input_vars=["load"], result_vars=["distance"])
    bench.report.append(res.to_line())

    return bench


if __name__ == "__main__":
    bn.run(example_plot_line, subsampling_divisions=3)