iso-bench
Version:
Small benchmark library focused in avoiding optimization/deoptimization pollution between tests by isolating them.
34 lines (33 loc) • 1.42 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatColor = formatColor;
exports.getTestLog = getTestLog;
function formatColor(str, color, useColor) {
return useColor ? `${color}${str}${"\u001B[0m"}` : str;
}
function getTestLog(padding, test, minMax, useColor, sample) {
const logArgs = [test.name.padEnd(padding, " "), "-"];
if (test.error) {
logArgs.push(formatColor(test.error, "\u001B[31m", useColor));
}
else {
logArgs.push(formatColor(Math.round((sample ? sample.ops : test.opMs) * 1000).toLocaleString(), "\u001B[36m", useColor));
if (!sample && test.samples.length > 1) {
logArgs.push("op/s.", formatColor(String(test.samples.length), "\u001B[36m", useColor), "samples in");
}
else {
logArgs.push("op/s in");
}
logArgs.push(formatColor(String(Math.round(sample ? sample.time : test.totalTime)), "\u001B[36m", useColor), "ms.");
if (minMax) {
logArgs.push(formatColor(`${(test.opMs / minMax.min).toFixed(3)}x`, "\u001B[36m", useColor));
if (test.opMs === minMax.min) {
logArgs.push(formatColor(`(WORST)`, "\u001B[33m", useColor));
}
else if (test.opMs === minMax.max) {
logArgs.push(formatColor(`(BEST)`, "\u001B[32m", useColor));
}
}
}
return logArgs;
}
;