import '../../assert_dev_env.js';
import { Benchmark } from '@fuzdev/fuz_util/benchmark.js';
/**
 * Network-tuned defaults — fuz_util's micro-benchmark defaults (warmup 10,
 * min 30, duration 1000ms) are sized for sub-microsecond functions. RPC round
 * trips are millisecond-scale and IO-bound, so warm the connection more and
 * collect a higher sample floor for stable tail percentiles.
 */
const DEFAULT_BENCH_CONFIG = {
    warmup_iterations: 20,
    min_iterations: 100,
    duration_ms: 3000,
    cooldown_ms: 100,
};
export const run_cross_impl_bench = async (options) => {
    const config = { ...DEFAULT_BENCH_CONFIG, ...options.config };
    const entries = [];
    for (const handle of options.handles) {
        const ctx = {
            transport: handle.keeper_transport,
            rpc_path: handle.config.rpc_path,
            capabilities: handle.config.capabilities,
        };
        for (const scenario of options.scenarios) {
            if (scenario.requires && !scenario.requires(handle.config.capabilities))
                continue;
            // One task per Benchmark, named by the backend so the report tables
            // read as backend rows under a per-scenario heading.
            const bench = new Benchmark(config);
            bench.add({ name: handle.config.name, fn: () => scenario.run(ctx), async: true });
            const [result] = await bench.run();
            entries.push({ backend: handle.config.name, scenario: scenario.name, result: result });
        }
    }
    const backends = options.handles.map((h) => h.config.name);
    const scenarios = [...new Set(entries.map((e) => e.scenario))];
    return { backends, scenarios, entries };
};
