(function (root) {
"use strict";
var PREFIX = "CLI execution - ";
var PAIRS = [
{ mode: "short", retch: PREFIX + "retch --short", fastfetch: PREFIX + "fastfetch (short)" },
{ mode: "default", retch: PREFIX + "retch", fastfetch: PREFIX + "fastfetch (default)" },
{ mode: "long", retch: PREFIX + "retch --long", fastfetch: PREFIX + "fastfetch (long)" },
{ mode: "full", retch: PREFIX + "retch --full", fastfetch: PREFIX + "fastfetch (full)" },
];
var VERSION = /^v\d+\.\d+\.\d+/;
function extraOf(entry) {
var benches = entry.benches || [];
for (var i = 0; i < benches.length; i++) {
if (typeof benches[i].extra === "string" && VERSION.test(benches[i].extra)) {
return benches[i].extra;
}
}
return null;
}
function pointLabel(entry) {
var extra = extraOf(entry);
if (extra) return extra.split("; ")[0];
var id = (entry.commit && entry.commit.id) || "";
return id.slice(0, 7) || "?";
}
function powerOf(entry) {
var extra = extraOf(entry);
if (!extra) return null;
var power = extra.split("; ")[1];
return power === "AC" || power === "battery" ? power : null;
}
function ms(entry, name) {
var benches = entry.benches || [];
for (var i = 0; i < benches.length; i++) {
var b = benches[i];
if (b.name === name && typeof b.value === "number" && b.unit === "ns") {
return b.value / 1e6;
}
}
return null;
}
function ratioSeries(entries, pair) {
var out = [];
entries.forEach(function (e) {
var r = ms(e, pair.retch);
var f = ms(e, pair.fastfetch);
if (r !== null && f !== null && f > 0) {
out.push({ label: pointLabel(e), power: powerOf(e), ratio: r / f, retch: r, fastfetch: f });
}
});
return out;
}
function absoluteSeries(entries, name) {
var out = [];
entries.forEach(function (e) {
var v = ms(e, name);
if (v !== null) out.push({ label: pointLabel(e), power: powerOf(e), ms: v });
});
return out;
}
function otherSeriesNames(entries) {
var paired = {};
PAIRS.forEach(function (p) {
paired[p.retch] = true;
paired[p.fastfetch] = true;
});
var seen = {};
entries.forEach(function (e) {
(e.benches || []).forEach(function (b) {
if (!paired[b.name]) seen[b.name] = true;
});
});
return Object.keys(seen).sort();
}
function suiteNames(data) {
var names = Object.keys((data && data.entries) || {});
var local = names.filter(function (n) { return n.indexOf("Local") === 0; }).sort();
var ci = names.filter(function (n) { return n.indexOf("Local") !== 0; }).sort();
return local.concat(ci);
}
var api = {
PAIRS: PAIRS,
pointLabel: pointLabel,
powerOf: powerOf,
ms: ms,
ratioSeries: ratioSeries,
absoluteSeries: absoluteSeries,
otherSeriesNames: otherSeriesNames,
suiteNames: suiteNames,
};
root.RetchBench = api;
if (typeof module !== "undefined" && module.exports) module.exports = api;
})(typeof window !== "undefined" ? window : globalThis);