diff --git a/trailer.html b/trailer.html index 431547e..10db796 100644 --- a/trailer.html +++ b/trailer.html @@ -325,6 +325,31 @@ return out.join(""); } + function mmss(n) { + return Math.floor(n / 60) + ":" + String(Math.round(n % 60)).padStart(2, "0"); + } + + // The header's runtime is the sum of what the writer typed. This is what the + // lines take when the cast actually says them, which is a different number + // and the only one worth cutting against. + function timingHtml() { + var t = PKG.timing; + if (!t || !t.measured_seconds) return ""; + var over = Number(t.over_by || 0); + var line = "Spoken by the cast this script runs " + mmss(t.measured_seconds) + + ", against a " + mmss(t.target_seconds) + " target"; + if (over > 5) line += " — " + Math.round(over) + " seconds over." + + " Revising the whole script will cut that much."; + else if (over < -15) line += " — " + Math.round(-over) + " seconds short."; + else line += " — that fits."; + var worst = (t.longest_lines || []).slice(0, 3).map(function (l) { + return "