UNPKG

@c4312/matcha

Version:

A caffeine driven, simple command line for benchmarking

63 lines 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const os_1 = require("os"); exports.jsonSummaryFactory = { description: 'Outputs summarized stats as raw JSON', start: () => new JsonSummaryReporter(process.stdout), }; class JsonSummaryReporter { constructor(out) { this.out = out; this.results = []; } onStartCycle() { // no-op } onFinishCycle(newResult) { this.results.push(newResult); } onComplete() { var _a; const benchmarks = []; const results = []; const errors = []; let minHz = Infinity; let maxHz = 0; let elapsed = 0; let fastest; for (const benchmark of this.results) { elapsed += benchmark.times.elapsed; if (benchmark.error) { errors.push({ name: benchmark.name, error: benchmark.error.stack }); } else { minHz = Math.min(minHz, benchmark.hz); if (benchmark.hz > maxHz) { maxHz = benchmark.hz; fastest = benchmark; } benchmarks.push(benchmark); } } for (const benchmark of benchmarks) { const factor = benchmark.hz / minHz; results.push({ name: benchmark.name, factor: Number(factor.toFixed(2)), ops: Number(benchmark.hz.toPrecision(3)), fastest: benchmark === fastest, }); } const result = { benches: this.results.length, errors, fastest: (_a = fastest) === null || _a === void 0 ? void 0 : _a.name, elapsed: Number(elapsed.toFixed(2)), results, }; this.out.write(JSON.stringify(result)); this.out.write(os_1.EOL); } } exports.JsonSummaryReporter = JsonSummaryReporter; //# sourceMappingURL=json-summary.js.map