"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.bench = bench;
const node_perf_hooks_1 = require("node:perf_hooks");
// Generic benchmark runner
function bench(logger, label, runnerFactory, iterations) {
    return __awaiter(this, void 0, void 0, function* () {
        const run = yield runnerFactory();
        const samples = [];
        for (let i = 0; i < iterations; i++) {
            const t0 = node_perf_hooks_1.performance.now();
            yield run(); // ← real work
            samples.push(node_perf_hooks_1.performance.now() - t0);
        }
        const mean = samples.reduce((s, n) => s + n, 0) / samples.length;
        const min = Math.min(...samples);
        const max = Math.max(...samples);
        logger.info(`${label.padEnd(12)}  avg ${mean.toFixed(2)} ms   ` +
            `(min ${min.toFixed(2)} / max ${max.toFixed(2)})`);
    });
}
//# sourceMappingURL=utils.js.map